Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking CustomErrors turned on in Code

Is it possible to check weather custom errors is turned on or off in the code on web application runtime.

like image 437
Naz Avatar asked Sep 02 '09 13:09

Naz


People also ask

Where do you put customErrors mode off?

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web. config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

What is customErrors mode?

CustomErrors supports the following modes: On – If defaultRedirect is specified, they will see that content. Otherwise, the default error screen with fewer details. Off – Detailed error details will be shown to the user. (the “yellow screen of death screen”)

Which code will enable custom error in web config?

The <customErrors> element under system. web in web. config is used to configure error code to a custom page. It can be used to configure custom pages for any error code 4xx or 5xx.


2 Answers

I've figured out how to do it it's in...

HttpContext.Current.IsCustomErrorEnabled

like image 57
Naz Avatar answered Oct 13 '22 22:10

Naz


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());
like image 21
Paul Turner Avatar answered Oct 13 '22 20:10

Paul Turner