0

我正在将一个 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 内部错误。

4

1 回答 1

0

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

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

于 2017-09-13T10:19:13.987 回答