簡體   English   中英

自定義404錯誤頁面無法在IIS 8.5上運行

[英]Custom 404 error page not working on IIS 8.5

我最近移動了主機,不得不在IIS中再次設置客戶錯誤。

我可以按如下方式轉到IIS Admin和Error Pages:

IIS上的自定義錯誤

然后我可以轉到自定義錯誤,並設置如下選項:

客戶錯誤設置

這將創建我的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錯誤頁面位於正確的位置。

我看不出還有什么需要做的。

得到它最終工作(幫助找到這個: 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>

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

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

如果我在控制器中返回以下內容,我也沒有收到我的自定義錯誤頁面:

return HttpNotFound();

如果我設置PassThrough,我可以將IIS默認錯誤更改為空白頁:

<httpErrors existingResponse="PassThrough" />

將其更改為“替換”會使默認的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>

我已經將所有這些細節都放在這里,所以這有希望出現給其他人搜索我做過的同樣的事情 - 希望它有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM