Code

2009-09-02 9 views
8

'da CustomErrors özelliğini açık konuma getirme Web uygulama çalışma zamanında kodda hava durumu özel hatalarının açık veya kapalı olduğunu kontrol etmek mümkün müdür?Code

cevap

13

.. .

HttpContext.Current.IsCustomErrorEnabled

3

Sen özel hata engellemek almak için kullanabilirsiniz sonra, web sitesi için yapılandırmayı elde etmek WebConfigurationManager.OpenWebConfiguration kullanabilirsiniz: Ben İçinde nasıl anladım

Configuration configuration = 
    WebConfigurationManager.OpenWebConfiguration(null); 

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

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

'OpenWebConfiguration (null)' mevcut uygulamada web.config ama makinede yüklü web.config yüklemek için görünmüyor. Diğer cevaplar 'OpenWebConfiguration (" ~ ")' dır ancak doğrulamamışımdır. – Buildstarted

0

OpenWebConfiguration (doğru) (null) veya HttpContext.Current.IsCustomErrorEnabled, bana yanlış bilgi verdi Bu ancak büyük Kopya macunu çalıştı:

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

    return ((CustomErrorsSection)config.GetSection("system.web/customErrors")).Mode; 
} 
İlgili konular