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
等几个重要事件。那么究竟是什么问题呢?
感谢达林,但仍然没有工作! – Sadegh 2011-04-10 09:13:46