表单数据在身份验证过程中丢失 - 但仅限于集成管道模式

时间:2011-08-23 14:46:36

标签: asp.net-mvc iis-7 forms-authentication integrated-pipeline-mode

我维护一个ASP.NET MVC应用程序(版本1),该应用程序当前在经典模式下运行在IIS 7上。我们想开始以集成管道模式运行应用程序。但是,我遇到了一个阻止我们切换到集成模式的奇怪问题 - 当我们尝试时,应用程序停止接收表单数据。 (即通过POST方法发送数据。)

通过向Global.aspx文件添加大量日志记录,我能够缩小表单数据丢失的位置。这是似乎正在发生的事情。

  1. 收到请求后,会触发Application_BeginRequest个事件。此时,表单数据存在,可以通过检查请求对象的FormsParams属性来查看。此时请求的Url属性在其中的任何位置都有“.mvc”扩展名。 (更多内容见下文。)

  2. 接下来,触发Application_AuthenticateRequest事件。同样,表单数据存在,URL没有“.mvc”扩展名。

  3. 此时,我预计会发生Application_PostAuthenticateRequest事件。但 acutally 发生的是再次调用Application_BeginRequest。这一次,表单数据已经消失 - 它不在FormsParams或其他任何地方。此外,URL已更改,以便Url的控制器名称部分添加了“.mvc”扩展名。例如,如果步骤1和2中的URL为“/ Education / Manage”,则在步骤3中显示为“/Education.mvc/Manage”。

  4. 再次触发Application_AuthenticateRequest事件。同样,表单数据丢失,URL中嵌入了“.mvc”扩展名。

  5. 这一次,Application_PostAuthenticateRequest被触发,页面的其余部分生命周期正常进行。在此事件和所有后续事件中,没有表单数据,并且“.mvc”扩展名仍然存在。

  6. 仅当我切换到集成管道模式时才会出现此问题。它在经典模式下工作正常。我一直在谷歌搜索几天,不幸的是我一直无法找到任何类似问题的参考。我也试过用几种不同的方式编辑Web.config文件,希望能解决问题,没有任何运气。我希望这里有人可以解决这个问题。

    以下是一些相关的代码段。如果我应该包含任何其他代码,请告诉我。

    来自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>
    

    来自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));
                }
            }
        }
    

1 个答案:

答案 0 :(得分:2)

您是否有机会使用URL重写器或通配符映射来支持经典模式? 不需要这用于集成模式,应将其关闭。

相关问题