2017-09-13 125 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內部錯誤。

回答

相關問題