2015-07-05 112 views
7

我最近移動了主機,並且必須在IIS中再次設置客戶錯誤。自定義404錯誤頁面不能在IIS 8.5上工作

我可以去IIS管理和錯誤頁面如下:

Custom Errors on IIS

然後我可以去自定義錯誤,並且已經設置了選項如下:

Customer Errors setup

這創建我的web.config文件如下:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="ExecuteURL"> 
      <remove statusCode="500" subStatusCode="100" /> 
      <remove statusCode="500" subStatusCode="-1" /> 
      <remove statusCode="404" subStatusCode="-1" /> 
      <error statusCode="404" prefixLanguageFilePath="" path="/error_404.asp" responseMode="ExecuteURL" /> 
      <error statusCode="500" prefixLanguageFilePath="" path="/error_500.asp" responseMode="ExecuteURL" /> 
      <error statusCode="500" subStatusCode="100" path="/error_500.asp" responseMode="ExecuteURL" /> 
     </httpErrors> 
    </system.webServer> 
</configuration> 

當我測試頁面時,505錯誤工作正常,並重定向到正確的頁面,但404不重定向並返回標準的IIS 404錯誤。我已確認404錯誤頁面在服務器上的正確位置。

我看不到我還需要做什麼。

+0

考慮發佈解決方案作爲答案並接受它。否則,將來可能會刪除沒有任何答案的問題。 –

+0

感謝您的建議 - 完成。 – 4532066

回答

6

得到它到底工作(通過尋找這有助於:http://forums.iis.net/t/1173965.aspx),使用:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> 
      <remove statusCode="500" subStatusCode="100" /> 
      <remove statusCode="500" subStatusCode="-1" /> 
      <remove statusCode="404" subStatusCode="-1" /> 
      <error statusCode="404" path="/error_404.asp" responseMode="ExecuteURL" /> 
      <error statusCode="500" prefixLanguageFilePath="" path="/error_500.asp" responseMode="ExecuteURL" /> 
      <error statusCode="500" subStatusCode="100" path="/error_500.asp" responseMode="ExecuteURL" /> 
     </httpErrors> 
    </system.webServer> 
</configuration> 
2

我有一個類似的問題,我在/錯誤/缺少有一個自定義404頁,但那一點都不t顯示不存在的靜態文件或DID存在的文件夾/目錄(但不應由MVC提供)。丟失的頁面控制器有以下幾點:

Response.AddHeader("Content-Type","text/html; charset=utf-8"); 
    Response.TrySkipIisCustomErrors = true; 
    Response.StatusCode = (int)HttpStatusCode.NotFound; // 404 

而且我沒有得到我的自定義錯誤頁,如果我回到控制器中的以下內容:

return HttpNotFound(); 

我可以改變IIS默認錯誤如果我設置了PassThrough,則爲空白頁面:

<httpErrors existingResponse="PassThrough" /> 

將其更改爲「Replace」會使默認IIS錯誤再次顯示。

我也在我的web.config中有一個部分,但我已經把它拿出來了,因爲我是IIS 8.5,它看起來不再需要它了。

<system.web> 
    <customErrors mode="Off"> 
</system.web> 

所以基本上我無法擺脫默認的IIS消息 - 無論是單線還是更詳細的。我httpErrors部分是這樣的:

<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> 
    <remove statusCode="404" /> 
    <error statusCode="404" path="/Error/Missing" /> 
</httpErrors> 

最後我碰到這個問題來了,我一直在尋找在這個問題上對方的回答,並意識到,我可以嘗試每個錯誤線ResponseMode。我認爲這不是必要的,因爲我有defaultResponseMode設置 - 但它有所作爲!

所以,如果你想成爲一個自定義404頁使用此httpErrors模塊:

<httpErrors errorMode="Custom"> 
    <remove statusCode="404" /> 
    <error statusCode="404" path="/Error/Missing" responseMode="ExecuteURL" /> 
</httpErrors> 

我已經把所有這些細節這裏,所以這個希望顯示出來別人搜索我做同樣的事情- 希望能幫助到你!