启动应用程序时出错。
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>
这是错误的屏幕截图:
答案 0 :(得分:0)
我认为您可能已经颠覆了集成模式和经典模式 - 至少从配置文件中的注释看起来就是这样。
system.web用于较旧的Classic模式,system.webserver用于集成模式。请参阅以下SO answer以供参考。
如果您在通常属于另一个的配置设置中有一些我可以看到您收到此错误。
答案 1 :(得分:0)
是否可以尝试使用IIS 7.5
<system.webServer>
<modules>
<add name="UserIdModule" type="My.Web.UserIdModule"/>
</modules>
</system.webServer>