0

ああ、この問題を解決するために、私の頭は完全に忙しいです。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。では、実際に何が問題なのでしょうか?

4

1 に答える 1

0

このモジュールへのアクセスに使用する URL をルーティング エンジンから除外してみてください。

routes.IgnoreRoute("UrlNormalizerModule.ashx");
于 2011-04-10T07:48:49.000 に答える