ああ、この問題を解決するために、私の頭は完全に忙しいです。httpmodule を登録すると、not-found エラーが発生します。それ以外の場合は、すべてが魅力的に機能します。
ここに私の 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。では、実際に何が問題なのでしょうか?