2016-07-21 3 views
0

Мы переместили наши веб-сайты umbraco v4 со старого сервера с IIS6 на новый, работающий на IIS8.5. Сайты используют UrlRewriteModule, чтобы скрыть имя страницы в URL-адресах, однако все страницы, кроме главной страницы return 404 не найден. Может кому-то помочь. Спасибо!UrlRewriteModule не работает над 8.5

Это немного кода, регистрируя URL Rewrite модуль -

<system.webServer> 
    <modules> 
    <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" /> 
    </modules> 
</system.webServer> 

Я попробовал следующее (предложил другой поток переполнения стека), но я все еще есть error.-

Скопируйте определение HttpModules в файле web.config из system.web в system.webServer

<system.web> 
     <httpModules> 
      <add name="UrlRewriteModule"type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" /> 
     </httpModules> 
</system.web> 

    <system.webServer> 
    <modules> 
     <add name="UrlRewriteModule"type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" /> 
    </modules> 
<system.webServer> 

UrlRewriting.config -

<?xml version="1.0" encoding="utf-8"?> 
<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07"> 
    <rewrites> 
     <!-- 
       Urlrewriting.Net is a cool tool, what can make your urls look nice. 
       The rewriting is controlled with regular expressions. To get more help 
       look at http://www.urlrewriting.net/. 

       Remember to read the manual! 
       http://www.urlrewriting.net/download/UrlRewritingNet20.English.pdf 

       The sample below rewrites a url from 
       "/product/someproductid.aspx" to 
       "/product.aspx?productid=someproductid" 

       The user will not see the rewritten path! The page that will be 
       loaded from umbraco will instead be: 
       "/product.aspx?productid=someproductid" 

       <add name="produktidrewrite" 
        virtualUrl="^~/product/(.*).aspx" 
        rewriteUrlParameter="ExcludeFromClientQueryString" 
        destinationUrl="~/product.aspx?productid=$1" 
        ignoreCase="true" /> 

       This sample is usefull for a productpage, where the product comes from a 
       dynamic datasource, e.g. a database. The querystring "productid" can be loaded 
       from the template, into a macro, that then loads the product! 

       Any bugs or problems with the rewriter, contact Anders/Duckie 
      --> 

     <add name="test" 
        virtualUrl="^~/technology/(.*).aspx" 
        rewriteUrlParameter="ExcludeFromClientQueryString" 
        destinationUrl="~/technology/default.aspx" 
        ignoreCase="true" /> 


    </rewrites> 
</urlrewritingnet> 

Я попробовал этот Vb класс, который я видел на другом сайте, но после его регистрации в моем WebConfig его до сих пор не работает -

Imports System 
Imports System.Web 
Imports System.Data 

Public Class URLRedirector 
    Implements IHttpModule 

    Private mdsRedirect As DataSet 

    Public Sub Init(ByVal TheApp As HttpApplication) Implements IHttpModule.Init 
     AddHandler TheApp.BeginRequest, AddressOf Me.Application_BeginRequest 
     ' Cache the redirection file in a dataset. 
     mdsRedirect = New DataSet() 
     mdsRedirect.ReadXml(HttpContext.Current.Server.MapPath("~/App_Data/Redirection.xml")) 
    End Sub 

    Public Sub Dispose() Implements IHttpModule.Dispose 
     mdsRedirect = Nothing 
    End Sub 

    Private Sub Application_BeginRequest(ByVal Source As Object, ByVal e As EventArgs) 
     Dim oApp As HttpApplication = CType(Source, HttpApplication) 
     Dim strRequestUri As String 

     strRequestUri = oApp.Request.Url.AbsoluteUri.ToLower() 

     ' OPTION 1: Process all requests (use when running in Visual Studio)... 
     ' Redirect known paths and just let the others fall through. 
     ' Call RedirectKnownPath(oApp, strRequestUri) 

     ' OPTION 2: Process only the 404 requests (use when running under IIS)... 
     ' For this module to work under IIS, you must configure the web site to redirect 
     ' all 404 requests back to the application. 
     If strRequestUri.Contains("?404;") Then 
      If Not RedirectKnownPath(oApp, strRequestUri) Then 
       ' Send all 404 requests for unknown paths to the default page. 
       oApp.Response.Redirect("~/Default.aspx") 
      End If 
     End If 
    End Sub 

    Private Function RedirectKnownPath(ByVal oApp As HttpApplication, ByVal strRequestUri As String) As Boolean 
     Dim strOriginalUri As String = strRequestUri 
     Dim intPos As Integer 
     Dim boolPathRedirected As Boolean = False 
     Dim oRow As DataRow 
     Dim strRequestPath As String 
     Dim strDestinationUrl As String 

     ' Extract the original URL if you received a 404 URL. 
     intPos = strRequestUri.IndexOf("?404;") 
     If intPos > 0 And strRequestUri.Length > (intPos + 5) Then 
      strOriginalUri = strRequestUri.Substring(intPos + 5) 
     End If 

     ' Redirect the request if you find a matching request path. 
     For Each oRow In mdsRedirect.Tables(0).Rows 
      strRequestPath = Convert.ToString(oRow("RequestPath")).ToLower() 
      If strOriginalUri.EndsWith(strRequestPath) Then 
       strDestinationUrl = Convert.ToString(oRow("Target")) 
       Call oApp.Response.Redirect(strDestinationUrl, False) 
       boolPathRedirected = True 
       Exit For 
      End If 
     Next 

     Return boolPathRedirected 
    End Function 
End Class 
+0

Вы можете включить правила перезаписи из config.xml. Кроме того, если вы включите функцию Failed Request Tracing, вы сможете получить дополнительную информацию об ошибке. –

+0

Привет, Фил. Конфигурация UrlRewriting отображает едва ли что-либо, поэтому я добавил запись под названием test, по-прежнему получаю ту же ошибку. –

+0

Я также включил Failed Request Tracing. –

ответ

1

Я бы не использовать модуль UrlRewrite, который поставляется с Umbraco, это OK для более мелкого материала, но он не работает так хорошо. Я считаю, что в какой-то момент он удаляется из ядра (возможно, V8).

Вам будет намного лучше использовать модуль перезаписи URL-адреса IIS, который выполняется как часть конвейера IIS и намного быстрее. Он также поддерживает больше функций.

Вы можете узнать о модуле здесь: http://www.iis.net/downloads/microsoft/url-rewrite

+0

Привет, Тим, это очень понравилось! –

Смежные вопросы