Asp.net

IIS 中的 existingResponse=‘PassThrough’ 是什麼意思?

  • June 25, 2015

文件說

existingResponse="PassThrough"

如果存在現有響應,則保持響應不變。 <http://www.iis.net/configreference/system.webserver/httperrors#005>

但是,“現有的反應存在”是什麼意思?

例如,我希望我的customErrors處理程序抑制 ASP.NET 響應,以便 IIS 認為該響應不存在。我該怎麼做?

架構中存在三個可能的值:

&lt;attribute name="existingResponse" type="enum" defaultValue="Auto"&gt;
 &lt;enum name="Auto" value="0" /&gt;
 &lt;enum name="Replace" value="1" /&gt;
 &lt;enum name="PassThrough" value="2" /&gt;
&lt;/attribute&gt;

大致來說,我是這樣理解的:

PassThrough - 留下現有的響應,只要有一個。您的應用程序邏輯可能不會返回任何內容。在這種情況下,使用此處定義的錯誤頁面。

自動- 使用此節點中定義的 IIS 錯誤頁面,除非您在 asp.net 中設置:

Response.TrySkipIisCustomErrors = true;

如果您這樣做了,則使用您的程式碼的響應。

替換- 始終使用 IIS 錯誤頁面,即使開發人員已設置TrySkipIisCustomErrors.

最後一個選項似乎是您想要的。


編輯:

考慮:

existingResponse="PassThrough"

現在嘗試打開一個不存在的 asp.net 頁面,你會看到:

在此處輸入圖像描述

即使資源不存在,執行時也會提供響應,並將其傳遞給瀏覽器。

現在,嘗試打開一個不存在的 html 頁面。這次我們仍然得到一個 404 狀態但是一個空頁面。

更改為:

existingResponse="Auto"

缺少的 asp.net 頁面仍然顯示 asp.net 錯誤頁面,但是對於缺少的 html 頁面,我們現在得到 IIS 頁面:

在此處輸入圖像描述

因此,總結一下:當查看具有不同 existingResponse值的缺失 html 和 aspx 頁面時,我們會得到不同的錯誤頁面:

               .html-404   .aspx-404   .aspx-500
--------------------------------------------------
Auto             IIS         asp.net    asp.net
PassThrough      -           asp.net    asp.net
Replace          IIS         IIS        IIS

引用自:https://stackoverflow.com/questions/31040671