问题
Is it possible to check weather custom errors is turned on or off in the code on web application runtime.
回答1:
I've figured out how to do it it's in...
HttpContext.Current.IsCustomErrorEnabled
回答2:
You can use WebConfigurationManager.OpenWebConfiguration to obtain the configuration for the website, then use that to get the custom errors block:
Configuration configuration =
WebConfigurationManager.OpenWebConfiguration(null);
CustomErrorsSection customErrorsSection =
configuration.GetSection("system.web/customErrors") as CustomErrorsSection;
Response.Write(customErrorsSection.Mode.ToString());
回答3:
OpenWebConfiguration(null) or HttpContext.Current.IsCustomErrorEnabled(true) gave me false information, this however worked great Copy paste:
public static CustomErrorsMode GetRedirectMode()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("/");
return ((CustomErrorsSection)config.GetSection("system.web/customErrors")).Mode;
}
来源:https://stackoverflow.com/questions/1367640/checking-customerrors-turned-on-in-code