我正在将一个 HTML 站点迁移到 ASP.Net 4.0 Web 应用程序。如果有人键入现有的 HTML 页面 URL,我想将他们重定向到相应的 ASP 页面。
我已经尝试了以下建议,但没有成功。
包含重定向到 web.config 中的某个 asp 页面的自定义错误标记 - 不起作用
enter code here <customErrors mode="On"> <error statusCode="404" redirect="~/Error.aspx" /> </customErrors> enter code here
包含在 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
尝试在 web.cofig 中使用 httpErrors 标记 - 它会引发 500 内部错误。