簡體   English   中英

通過web.config進行的自定義錯誤重定向不起作用

[英]Custom error redirection through web.config does not work

當發生錯誤時,我正在嘗試實現重定向到自定義錯誤頁面的操作。

我嘗試了另一種方式:

<customErrors mode="On" redirectMode="ResponseRewrite">
  <error statusCode="403" redirect="/Errors/AccessDenied" />
  <error statusCode="404" redirect="/Errors/PageNotFound" />
</customErrors>

還有在web.server標記中帶有<httperrors>方法。

這些方法均無效。 我看到默認錯誤,而不是重定向到錯誤頁面:

愚蠢的錯誤

您有什么建議可以解決該問題? 我將非常感謝您的幫助

屏幕似乎拋出了HTTP 404錯誤。 假設您沒有其他重寫方法來捕獲應用程序中的這些錯誤,請嘗試將以下內容添加到web.config中

<system.webServer>
   <httpErrors errorMode="Custom" existingResponse="Replace">
     <remove statusCode="404" />
     <error statusCode="404" path="/Errors/whatever" responseMode="ExecuteURL" />
   </httpErrors>
</system.webServer>

您嘗試刪除狀態碼404嗎?

<system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/Errors/PageNotFound" responseMode="ExecuteURL" />
    </httpErrors>
  </system.webServer>

暫無
暫無

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

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