IIS 7 does not fire Application Error in Global.asax while migrating a HTML application to ASP.NET 4.0

196 Views Asked by At

I am migrating a HTML site to ASP.Net 4.0 web application. If someone types an existing HTML page URL, I want to redirect them to a corresponding ASP page.

I have already tried below suggestions, nothing worked out.

  1. included Custom Errors tag which redirects to some asp page in web.config - not worked

    enter code here
    <customErrors mode="On">
      <error statusCode="404" redirect="~/Error.aspx" />
    </customErrors>
    enter code here
    
  2. included below code under Application_Error method in the Global.asax page. - It does not fire

    enter code here
    
    void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs
            string fullOrginalpath = Request.Url.ToString();
            string strPathExtn = 
                Request.CurrentExecutionFilePathExtension.ToString();
            if (fullOrginalpath.Contains(".html"))
            {
                Server.ClearError();
                Response.Clear();
                fullOrginalpath = fullOrginalpath.Replace(".html", ".aspx");
                Response.Redirect(fullOrginalpath);
            }           
        }
    enter code here
    
  3. Tried having httpErrors tag in web.cofig - it throws 500 internal error.

1

There are 1 best solutions below

1
On BEST ANSWER

I think you may want to look at the IIS URL Rewrite module:

https://www.iis.net/downloads/microsoft/url-rewrite