سؤال

I maintain an ASP.NET MVC application (version 1) that currently runs on IIS 7 in classic mode. We'd like to start running the app in integrated pipeline mode instead. However, I am running into a bizarre problem that is preventing us from switching to integrated mode-- when we try, the application stops receiving forms data. (I.e. data send via the POST method.)

By adding a ton of logging to the Global.aspx file, I was able to narrow down the location where the forms data is getting lost. Here's what seems to be happening.

  1. Upon receiving the request, the Application_BeginRequest event is fired. At this point, the forms data is present and can be seen by examining the request object's Forms or Params property. The request's Url property at this point does not have an ".mvc" extension anywhere in it. (More on this below.)

  2. Next, the Application_AuthenticateRequest event is fired. Again, the forms data is present, and the URL has no ".mvc" extension.

  3. At this point, what I would expect to happen is for the Application_PostAuthenticateRequest event to fire. But what acutally happens is that Application_BeginRequest is called again. This time, the forms data is gone-- it's not in Forms, Params, or anywhere else. In addition, the URL has changed so that the controller name part of the Url has an ".mvc" extension tacked onto it. For instance, if the URL in steps 1 and 2 is "/Education/Manage", then in step 3 it shows up as "/Education.mvc/Manage".

  4. The Application_AuthenticateRequest event is fired again. Again, the forms data is missing, and the URL has an ".mvc" extension embedded in it.

  5. This time, Application_PostAuthenticateRequest is fired, and the rest of the page's life cycle proceeds normally. In this and all subsequent events, there's no forms data, and the ".mvc" extension remains present.

The problem only occurs when I switch to the integrated pipeline mode. It works fine in classic mode. I've been googling for days, and unfortunately I've been unable to find any reference to a similar problem. I've also tried editing the Web.config file in several different ways hoping to solve the problem, without any luck. I'm hoping somebody here can shed some light on the issue.

Here are a few relevant code snippets. If there's any other code I should include, please let me know.

From Web.config:

<system.web>
    <authentication mode="Forms">
        <forms name=".appLive" timeout="60" enableCrossAppRedirects="true" path="/" />
    </authentication>
    [...]
</system.web>
[....]
<system.webServer>
    <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" />

        <remove name="FormsAuthenticationModule" />    
        <remove name="UrlAuthorization" />    
        <remove name="DefaultAuthentication" />    
        <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" />    
    </modules>
    <handlers>
        <remove name="AboMapperCustom-17403419" />
        <remove name="WebServiceHandlerFactory-Integrated" />
        <remove name="ScriptHandlerFactory" />
        <remove name="ScriptHandlerFactoryAppServices" />
        <remove name="ScriptResource" />
        <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="MvcHttpHandler" preCondition="integratedMode" verb="*" path="*.mvc" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.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" />
        <add name="AboMapperCustom-17403419" path="*.mvc" verb="GET,POST,HEAD,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,bitness32,runtimeVersionv2.0" responseBufferLimit="0" />
    </handlers>
</system.webServer>

From Global.aspx:

    public void Application_BeginRequest(Object source, EventArgs e)
    {
        HttpApplication application = source as HttpApplication;

        if (source != null)
        {
            if (application.Request.AppRelativeCurrentExecutionFilePath.Contains(".mvc"))
            {
                application.Context.RewritePath(application.Request.Url.PathAndQuery.Replace(".mvc", string.Empty));
            }
        }
    }
هل كانت مفيدة؟

المحلول

Are you by any chance using a URL rewriter or wildcard mapping to support classic mode? You don't need this for integrated mode and should turn it off.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top