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?
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.
Custom error mode setting has 3 possible values: On, Off, and RemoteOnly.
config settings, customErrors can be configured within the Machine. config, root web. config or your application's web. config file.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With