Question

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?

Was it helpful?

Solution

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;

OTHER TIPS

If I understand your question correctly, this should help (copied from msdn)

// Get the Web application configuration.
Configuration configuration =  WebConfigurationManager.OpenWebConfiguration( "/aspnetTest");

// Get the section.
CustomErrorsSection customErrorsSection = (CustomErrorsSection)configuration.GetSection("system.web/customErrors");

// Get the collection
CustomErrorCollection customErrorsCollection =  customErrorsSection.Errors;

// Get the currentDefaultRedirect
string currentDefaultRedirect =  customErrorsSection.DefaultRedirect;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top