2017-09-13 216 views
0

我正在将HTML网站迁移到ASP.Net 4.0 Web应用程序。如果有人键入现有的HTML页面URL,我想将它们重定向到相应的ASP页面。IIS 7在将HTML应用程序迁移到ASP.NET 4.0时不会引发Global.asax中的应用程序错误

我已经尝试了下面的建议,没有什么解决。

  1. 包括自定义错误标签,它重定向到一些ASP页面在web.config中 - 在Global.asax页下面的代码没有奏效

    enter code here 
    <customErrors mode="On"> 
        <error statusCode="404" redirect="~/Error.aspx" /> 
    </customErrors> 
    enter code here 
    
  2. 下的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内部错误。

回答

相关问题