2013-11-25 31 views
0

HI我試圖重定向頁面,如果HttpError是404 它正在完善本地主機上,而在直播現場是沒有的。頁面不是從應用程序錯誤重定向,

這裏是我的代碼

void Application_Error(object sender, EventArgs e) 
{ 
    // Code that runs when an unhandled error occurs 
    HttpException serverError = Server.GetLastError() as HttpException; 

    if (serverError != null) 
    { 
     int errorCode = serverError.GetHttpCode(); 

     if (errorCode == 404) 
     { 
      Server.ClearError(); 
      if (Request.Url.ToString().Contains("contact.php")) 
      { 
       Response.Redirect("contact-us.aspx"); 
      } 
     } 
    } 
} 

感謝。請告知如何讓這個工作在現場,

回答

0

我想通了。我不得不寫在web.config中的規則對什麼都頁我需要重定向

<system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="contact"> 
      <match url="^(contact).php$"/> 
      <action type="Redirect" redirectType="Permanent" url="https://www.example.com/contact-us.aspx" /> 
     </rule> 
    </rewrite> 
</system.webServer> 

這完美地工作在所有網頁上,我不得不重新定向。並且在global.asax中沒有添加任何代碼

0

嘗試Response.Redirect(「〜/ contact-us.aspx」);

1

爲什麼不使用web.config而不是global.asax文件?

<system.webServer> 
      <httpErrors> 
      <remove statusCode="404" subStatusCode="-1" />     
      <error statusCode="404" path="contact-us.aspx" responseMode="ExecuteURL" />     
      </httpErrors> 
     </system.webServer> 
+0

這對於只有一個頁面是有用的..我有更多的1頁來重定向 – dnts2012

相關問題