Pregunta

I've read all of the MVC-tagged posts and haven't seen a problem like mine or found anything that has led me to a solution so I'm hoping someone can point me in a direction.

I have a MVC 2 web app running under a web forms app on Win 2003/IIS6 and I'm migrating to Win 2008/IIS7.5. I've read about Integrated Pipeline mode and have made changes to the web config to include "System.webserver" elements for http handlers. The Default.aspx page loads then rewrites the incoming request for "domain/site1/site2/default.aspx" to "domain/site1/site2/" and the Homecontroller executes and Index view is loaded. The problem is that Url.Content and Html.ActionLink resolve to "/site1/site2/site2/" - note duplicate virtual directory. The URL isn't being changed by the rewrite so I can't figure out what is causing this.

Here's the webserver element from the web.config:

<system.webServer>
    <validation validateIntegratedModeConfiguration="true"/>

    <modules runAllManagedModulesForAllRequests="true">
        <remove name="ScriptModule"/>
        <remove name="UrlRoutingModule"/>
        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>

    <handlers>
        <remove name="WebServiceHandlerFactory-Integrated"/>
        <remove name="ScriptHandlerFactory"/>
        <remove name="ScriptHandlerFactoryAppServices"/>
        <remove name="ScriptResource"/>
        <remove name="UrlRoutingHandler"/>
        <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </handlers>
</system.webServer>

Here's the RegisterRoutes method:

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")


    routes.MapRoute( _
        "Default", _
        "{controller}.aspx/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
    )
    routes.MapRoute( _
        "Root", _
        "", _
        New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _
    )
End Sub

The AppPool is set to Integrated mode, Allow 32 bit apps=True, and Target Framework=2.0.
I've also tried Classic mode on the AppPool with no difference in behavior.

It runs correctly on my Win7 development box. Any ideas?

¿Fue útil?

Solución

After scouring SO and other sources, I found 21228660/url-content-doesnt-resolve-absolute-path-on-one-server-but-does-on-another which led me look at MVC 2 source code. It turns out that in the PathHelper class, it checks for HTTP Header "HTTP_X_ORIGINAL_URL" indicating an HTTP Rewrite. I added code in Default.aspx page before the RewritePath statement to remove "HTTP_X_ORIGINAL_URL"from the ServerVariables collection and all is well!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top