2012-05-08 29 views

Trả lời

11

Thanx nhãn hiệu, nó là hữu ích. Những gì tôi thực sự muốn hỏi là "làm thế nào để có được" defaultRedirect "tài sản của customErrors phần từ web.config của ứng dụng asp MV của tôi?".

Và câu trả lời, dựa trên bài viết của bạn là:

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

Nếu tôi hiểu câu hỏi của bạn một cách chính xác, điều này sẽ giúp (sao chép từ 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; 
Các vấn đề liên quan