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