繁体   English   中英

使用HTTP模块时出错-已检测到ASP.NET设置,该设置不适用于集成托管管道模式

[英]Error while working with HTTP Module - An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

启动应用程序时出现错误。

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.

我创建了一个HTTP模块,该模块从请求标头读取信息并将数据写入cookie。 这是代码。

namespace My.Web
{
    public class UserIdModule : IHttpModule
    {
        private HttpApplication httpApp;

        public void Init(HttpApplication application)
        {
            application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
        }


        private void Application_BeginRequest(Object source, EventArgs e)
        {
            // Create HttpApplication and HttpContext objects to access
            // request and response properties.
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            //Read header
            string userId = context.Request.Headers["user_id"];

            if (string.IsNullOrEmpty(userId))
            {
                userId = "guest";
            }

            //Create and write cookie
            HttpCookie userCookie = new HttpCookie("userId", userId);
            userCookie.Expires = DateTime.Now.AddYears(5);  
            context.Response.Cookies.Add(userCookie);
        }

        public void Dispose() { }
    }
}

在我的web.config中

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
    </staticContent>
    <!-- To register the module for IIS 6.0 and IIS 7.0 running in Classic mode -->
    <modules>
      <add name="UserIdModule" type="UserIdModule"/>
    </modules>
  </system.webServer>
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <!-- To register the module for IIS 7.0 running in Integrated mode -->
    <httpModules>
      <add name="UserIdModule" type="UserIdModule"/>
    </httpModules>
  </system.web>
</configuration>

这是错误的屏幕截图: 在此处输入图片说明

我认为您可能将“集成”模式和“经典”模式反转了-至少从配置文件中的注释中可以看出来。

system.web用于较旧的经典模式,system.webserver用于集成模式。 请参阅以下SO答案以供参考。

如果您有一个通常属于另一个的配置设置,我可能会看到此错误。

是IIS 7.5吗?

<system.webServer>
    <modules>
       <add name="UserIdModule"  type="My.Web.UserIdModule"/>
    </modules>
</system.webServer>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM