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.
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
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
Tried having httpErrors tag in web.cofig - it throws 500 internal error.
I think you may want to look at the IIS URL Rewrite module:
https://www.iis.net/downloads/microsoft/url-rewrite