【问题标题】:IIS 7 does not fire Application Error in Global.asax while migrating a HTML application to ASP.NET 4.0将 HTML 应用程序迁移到 ASP.NET 4.0 时,IIS 7 不会在 Global.asax 中触发应用程序错误
【发布时间】:2017-09-13 10:15:18
【问题描述】:

我正在将一个 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. 包含在 Global.asax 页面中 Application_Error 方法下的代码下方。 - 它不会触发

    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-7 global-asax application-error


    【解决方案1】:

    我想你可能想看看 IIS URL Rewrite 模块:

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

    【讨论】:

    • 感谢您提出的宝贵建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多