2009-09-02 19 views

Trả lời

13

Tôi đã tìm ra cách để làm điều đó nó ở .. .

HttpContext.Current.IsCustomErrorEnabled

3

Bạn có thể sử dụng WebConfigurationManager.OpenWebConfiguration để có được cấu hình cho các trang web, sau đó sử dụng để có được những lỗi tùy chỉnh chặn:

Configuration configuration = 
    WebConfigurationManager.OpenWebConfiguration(null); 

CustomErrorsSection customErrorsSection = 
    configuration.GetSection("system.web/customErrors") as CustomErrorsSection; 

Response.Write(customErrorsSection.Mode.ToString()); 
+0

'OpenWebConfiguration (null) 'dường như không nạp web.config trong ứng dụng hiện tại nhưng web.config được cài đặt trên máy tính này. Các câu trả lời khác cho thấy 'OpenWebConfiguration (" ~ ")' nhưng tôi chưa xác nhận. – Buildstarted

0

OpenWebConfiguration (null) hoặc HttpContext.Current.IsCustomErrorEnabled (true) đã cho tôi thông tin sai lệch, tuy nhiên điều này làm việc rất lớn Sao chép dán:

public static CustomErrorsMode GetRedirectMode() 
{ 
    Configuration config = WebConfigurationManager.OpenWebConfiguration("/"); 

    return ((CustomErrorsSection)config.GetSection("system.web/customErrors")).Mode; 
} 
Các vấn đề liên quan