繁体   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