我只想做以下事情:
var defaultRedirectUrl = SomeMethodToGetDefaultRedirect();
当然在 web.config 我有
<customErrors mode="On" defaultRedirect="~/Error"/>
这该怎么做?
我只想做以下事情:
var defaultRedirectUrl = SomeMethodToGetDefaultRedirect();
当然在 web.config 我有
<customErrors mode="On" defaultRedirect="~/Error"/>
这该怎么做?
谢谢马克,很有帮助。我真正想问的是“如何从我的 asp mvc 应用程序的 web.config 中获取 customErrors 部分的“defaultRedirect”属性?”。
根据您的帖子,答案是:
CustomErrorsSection customErrorsSection = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors");
string defaultRedirect = customErrorsSection.DefaultRedirect;
如果我正确理解您的问题,这应该会有所帮助(从 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;