簡體   English   中英

檢查Code中的CustomErrors已打開

[英]Checking CustomErrors turned on in Code

是否可以在Web應用程序運行時的代碼中檢查天氣自定義錯誤是打開還是關閉。

我已經弄清楚如何做到這一點......

HttpContext.Current.IsCustomErrorEnabled

您可以使用WebConfigurationManager.OpenWebConfiguration獲取網站的配置,然后使用它來獲取自定義錯誤塊:

Configuration configuration =
    WebConfigurationManager.OpenWebConfiguration(null);

CustomErrorsSection customErrorsSection =
    configuration.GetSection("system.web/customErrors") as CustomErrorsSection;

Response.Write(customErrorsSection.Mode.ToString());

OpenWebConfiguration(null)或HttpContext.Current.IsCustomErrorEnabled(true)給了我錯誤的信息,但這工作很棒復制粘貼:

public static CustomErrorsMode GetRedirectMode()
{
    Configuration config = WebConfigurationManager.OpenWebConfiguration("/");

    return ((CustomErrorsSection)config.GetSection("system.web/customErrors")).Mode;
}

暫無
暫無

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

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