2012-05-08 66 views

回答

11

感謝名單大關,這是有幫助的。 我真正想問的是「如何從我的asp mvc應用程序的web.config中獲取customErrors節的defaultRedirect屬性?」。

而答案,根據您的文章是:

CustomErrorsSection customErrorsSection = (CustomErrorsSection) ConfigurationManager.GetSection("system.web/customErrors"); 
     string defaultRedirect = customErrorsSection.DefaultRedirect; 
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;