How can I get customErrors' defaultRedirect value from code?
-
06-06-2021 - |
Pergunta
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?
Solução
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;
Outras dicas
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;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow