Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get customErrors' defaultRedirect value from code?

I would simply like to do something as follows:

var defaultRedirectUrl = SomeMethodToGetDefaultRedirect();

of course in web.config I have

<customErrors mode="On" defaultRedirect="~/Error"/>

How to do this?

like image 638
Fryderyq Avatar asked May 08 '12 23:05

Fryderyq


People also ask

What is the usage of defaultRedirect attribute in error handling?

Use the defaultRedirect to specify where an http request should be redirect by default if an error occurs. You can specify the name of a webform, an HTML, or an action method. This will redirect to this page on any error code, not just 500.

What are possible values for mode property of custom error page?

Custom error mode setting has 3 possible values: On, Off, and RemoteOnly.

In which file the customErrors is specified?

config settings, customErrors can be configured within the Machine. config, root web. config or your application's web. config file.


1 Answers

Thanx mark, it was helpful. What I really wanted to ask was "how to get "defaultRedirect" property of customErrors section from web.config of my asp mvc app?".

And the answer, based on your post is:

    CustomErrorsSection customErrorsSection = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors");
        string defaultRedirect = customErrorsSection.DefaultRedirect;
like image 175
Fryderyq Avatar answered Oct 08 '22 16:10

Fryderyq