2010-05-29 80 views
15

我有以下模塊的HttpModules不工作的IIS7

public class LowerCaseRequest : IHttpModule { 
    public void Init(HttpApplication context) { 
     context.BeginRequest += new EventHandler(this.OnBeginRequest); 
    } 

    public void Dispose() { } 

    public void OnBeginRequest(Object s, EventArgs e) { 
     HttpApplication app = (HttpApplication)s; 

     if (app.Context.Request.Url.ToString().ToLower().EndsWith(".aspx")) { 
      if (app.Context.Request.Url.ToString() != app.Context.Request.Url.ToString().ToLower()) { 
       HttpResponse response = app.Context.Response; 

       response.StatusCode = (int)HttpStatusCode.MovedPermanently; 
       response.Status = "301 Moved Permanently"; 
       response.RedirectLocation = app.Context.Request.Url.ToString().ToLower(); 
       response.SuppressContent = true; 
       response.End(); 
      } 
      if (!app.Context.Request.Url.ToString().StartsWith(@"http://zeeprico.com")) { 
       HttpResponse response = app.Context.Response; 

       response.StatusCode = (int)HttpStatusCode.MovedPermanently; 
       response.Status = "301 Moved Permanently"; 
       response.RedirectLocation = app.Context.Request.Url.ToString().ToLower().Replace(@"http://zeeprico.com", @"http://www.zeeprico.com"); 
       response.SuppressContent = true; 
       response.End(); 
      } 
     } 
    } 
} 

在web.config看起來像

<system.web> 
    <httpModules> 
     <remove name="WindowsAuthentication" /> 
     <remove name="PassportAuthentication" /> 
     <remove name="AnonymousIdentification" /> 
     <remove name="UrlAuthorization" /> 
     <remove name="FileAuthorization" /> 
     <add name="LowerCaseRequest" type="LowerCaseRequest" /> 
     <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" /> 
     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
</httpModules> 
</system.web> 

它可以運行XP我的電腦上爐排和IIS 5.1

但我的網絡服務器運行IIS7和WS 2008 dosn't工作,請幫助我不知道如何解決這個問題。

感謝

回答

35

在IIS7和更高的使用

<configuration> 
    <system.webServer> 
    <modules> 
     <add name="CustomModule" type="Samples.CustomModule" /> 
    </modules> 
    </system.webServer> 
</configuration> 
+0

謝謝, 因爲我的開發環境是iis5.0,所以我的生活環境是iis7 – roncansan 2010-05-29 16:02:33

+1

+1謝謝。他們去了什麼PITA並改變了這一點。 – Sam 2011-10-15 04:44:17

0

在IIS去功能視圖中選擇模塊

雙擊模塊,然後右鍵單擊並選擇(添加託管模塊)

然後把名稱和類型定義爲web.config

例如:

<httpModules> 
    <add name="CustomModule" type="WebApplication.Security.CustomModule" /> 
</httpModules> 
0

以上是IIS 7.5

<modules> 
    <add name="CustomModule" type="Samples.CustomModule" /> 
</modules> 

我唯一的問題是正確的,是應用程序池的特定應用程序的該實例應設置爲管理管道=集成,而不是經典..
或: 使用經典模式

如果應用程序是使用經典模式,然後確保你的應用程序配置爲該類型便便l並且您的模塊在system.web部分中配置,而不在web.config文件的system.webServer部分中配置。

相關問題