C# 使用HTTP模块时出错-检测到ASP.NET设置不适用于集成托管管道模式
我启动应用程序时出错C# 使用HTTP模块时出错-检测到ASP.NET设置不适用于集成托管管道模式,c#,asp.net,.net,asp.net-mvc-3,httpmodule,C#,Asp.net,.net,Asp.net Mvc 3,Httpmodule,我启动应用程序时出错 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 htt
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() { }
}
}
在my 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用于集成模式。参考如下
如果您在一个配置中有一些通常属于另一个的配置设置,我可以看到您出现此错误。是IIS 7.5吗
<system.webServer>
<modules>
<add name="UserIdModule" type="My.Web.UserIdModule"/>
</modules>
</system.webServer>
检查这些,