IIS 7在将HTML应用程序迁移到ASP.NET 4.0时不会在global.asax中发出应用程序错误



我正在将HTML站点迁移到ASP.NET 4.0 Web应用程序。如果有人键入现有的HTML页面URL,我想将它们重定向到相应的ASP页面。

我已经尝试了以下建议,没有解决。

  1. 包括自定义错误标签,将其重定向到Web.config中的某些ASP页面 - 不工作

    enter code here
    <customErrors mode="On">
      <error statusCode="404" redirect="~/Error.aspx" />
    </customErrors>
    enter code here
    
  2. 在application_error方法下,在global.asax页面中包含以下代码。 - 它不会开火

    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. 尝试在web.cofig中使用httperrors标签 - 它抛出500个内部错误。

我认为您可能想查看IIS URL重写模块:

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

相关内容

最新更新