frs frs - 9 months ago 59
C# Question

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?

frs frs
Answer Source

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;