2014-09-05 13 views
0

我在啓動我的應用程序時出錯。使用HTTP模塊時出錯 - 檢測到ASP.NET設置不適用於集成管理管道模式

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> 

這是錯誤的截圖:enter image description here

+0

檢查這些http://stackoverflow.com/questions/7370513/http-error-500-22-internal-server-error-an-asp-net -setting-has-been-detected,http://stackoverflow.com/questions/4209999/an-asp-net-setting-has-been-detected-that-does-not-apply-in-integrated-managed-p – malkam 2014-09-05 13:48:17

回答

0

我認爲你可能有集成和經典模式的逆轉 - 至少它看起來方式從您在配置文件中的評論。

system.web適用於較舊的Classic模式,system.webserver適用於Integrated模式。請參閱以下SO answer以供參考。

如果你有一些通常屬於另一個的配置設置,我可以看到你得到這個錯誤。

0

它是IIS 7.5可以嘗試

<system.webServer> 
    <modules> 
     <add name="UserIdModule" type="My.Web.UserIdModule"/> 
    </modules> 
</system.webServer> 
相關問題