0

Ah to solving this problem, my mind is completely busy. When i register my httpmodule, I get not-found error, otherwise everything works like a charm.

Here is my 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();
        }
    }
}

And how module is register in Web.config

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

UPDATE {temporarily problem solved}

Hm... I just handled all events of HttpApplication like below

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

I don't know why but above problem solved when i handled only few of important events such BeginRequest. So what is really a problem because?

Sadegh
  • 4,181
  • 9
  • 45
  • 78

1 Answers1

0

You may try excluding the URL used to access this modul from the routing engine:

routes.IgnoreRoute("UrlNormalizerModule.ashx");
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928