How can I get the defaultRedirect value for customErrors?

I just wanted to do something like the following:

var defaultRedirectUrl = SomeMethodToGetDefaultRedirect(); 

of course in web.config I have

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

How to do it?

+6
source share
2 answers

Thanx icon, that was helpful. I really wanted to ask, โ€œhow to get the defaultRedirect propertyโ€ of the customErrors section from the web.config of my asp mvc application? "

And the answer to your post:

  CustomErrorsSection customErrorsSection = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors"); string defaultRedirect = customErrorsSection.DefaultRedirect; 
+12
source

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; 
+12
source

Source: https://habr.com/ru/post/915242/


All Articles