2011-04-09 47 views
0

嗯,爲了解決這個問題,我的頭腦完全忙碌。當我註冊我的httpmodule時,我找不到錯誤,否則一切都像魅力一樣。ASP.NET MVC + IHttpModule =未找到

這裏是我的HttpModule

public class UrlNormalizerModule : HttpModuleBase { 
    protected override void OnBeginRequest(HttpContextBase context) { 
     var originUrl = HttpContext.Current.Request.Url.ToString(); 
     var normalizedUrl = originUrl.NormalizeUrl(false); 
     if (string.Compare(originUrl, normalizedUrl) != 0) { 
      var response = context.Response; 

      response.StatusCode = (int) HttpStatusCode.MovedPermanently; 
      response.Status = "301 Moved Permanently"; 
      response.RedirectLocation = normalizedUrl; 
      response.SuppressContent = true; 
      response.End(); 
     } 
    } 
} 

而且模塊是如何在Web.config中註冊

<system.webServer>   
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="UrlNormalizerModule" /> 
     <add name="UrlNormalizerModule" type="MagicByte.Web.Modules.UrlNormalizerModule, MagicByte.Web" /> 
    </modules> 
</system.webServer> 

更新{暫時問題解決了}

嗯...我只是處理HttpApplication的所有事件如下所示

context.AuthenticateRequest += 
      (sender, e) => OnAuthenticateRequest(new HttpContextWrapper(((HttpApplication) sender).Context)); 

我不知道爲什麼,但上面的問題解決了,當我只處理了BeginRequest等幾個重要事件。那麼究竟是什麼問題呢?

回答

0

您可以嘗試不包括用於從路由引擎訪問此MODUL的網址:

routes.IgnoreRoute("UrlNormalizerModule.ashx"); 
+0

感謝達林,但仍然沒有工作! – Sadegh 2011-04-10 09:13:46