Pages

Search This Blog

Friday, February 4, 2011

How to read 'mode' of customErrors Tag from the web.config file of Sharepoint Site

To handle the run time exceptions sometimes it is required to know what is the customErrors mode in the web.config file. The customErrors tag is available under system.web section group in web.config file.
<customErrors mode="Off" />
The below code snippet will help us in getting the mode of CustomErrors tag.
private string getCustomErrorMode()
        {
            System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/", Microsoft.SharePoint.SPContext.Current.Site.WebApplication.Name);
            System.Web.Configuration.CustomErrorsSection customErrors = (CustomErrorsSection)config.GetSection("system.web/customErrors");
            return Convert.ToString(customErrors.Mode);
        }

No comments:

Post a Comment