Click here to Skip to main content
15,905,232 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,

I have used a class file named: RewriteHttpModule in App_Code folder that have following code:
C#
public class RewriteHttpModule : IHttpModule
{
    public RewriteHttpModule()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest +=
        new System.EventHandler(this.context_BeginRequest);
    }


    public void Dispose()
    {
    }
    private void context_BeginRequest(object sender, EventArgs e)
    {
        HttpRequest request = ((HttpApplication)(sender)).Request;
        HttpContext context = ((HttpApplication)(sender)).Context;
        HttpResponse response = ((HttpApplication)(sender)).Response;
        string applicationPath = request.ApplicationPath;

        if ((applicationPath == "/"))
        {
            applicationPath = String.Empty;
        }

        string requestPath = request.Url.AbsolutePath.Substring(applicationPath.Length);
        if (requestPath.ToLower() == "/testurlrewrite.aspx")
        {
            context.RewritePath(applicationPath + "/testurlrewrite");
        }
        else if (requestPath.ToLower() == "/home.aspx")
        {
            context.RewritePath(applicationPath + "/home");
        }

    }
}

I my web config :

XML
<httpModules
      <add name="Localization" type="RewriteHttpModule" />
</httpModules>

For just to remove only .aspx from page URL, It works fine but server gives an error like :
C#
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.


What should i do to resolve this error?

Please help me.
Thanks.
Posted
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900