public string GenerateOutput(HttpContext context, Config c) { StringBuilder sb = new StringBuilder(); //Figure out CustomErrorsMode System.Configuration.Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null); CustomErrorsSection section = (configuration != null) ? section = (CustomErrorsSection)configuration.GetSection("system.web/customErrors") : null; CustomErrorsMode mode = (section != null) ? section.Mode : CustomErrorsMode.RemoteOnly; //What is diagnostics enableFor set to? DiagnosticMode dmode = c.get <DiagnosticMode>("diagnostics.enableFor", DiagnosticMode.None); //Is it set all all? bool diagDefined = (c.get("diagnostics.enableFor", null) != null); //Is it available from localhost. bool availLocally = (!diagDefined && mode == CustomErrorsMode.RemoteOnly) || (dmode == DiagnosticMode.Localhost); sb.AppendLine("The Resizer diagnostics page is " + (availLocally ? "only available from localhost." : "disabled.")); sb.AppendLine(); if (diagDefined) { sb.AppendLine("This is because <diagnostics enableFor=\"" + dmode.ToString() + "\" />."); } else { sb.AppendLine("This is because <customErrors mode=\"" + mode.ToString() + "\" />."); } sb.AppendLine(); sb.AppendLine("To override for localhost access, add <diagnostics enableFor=\"localhost\" /> in the <resizer> section of Web.config."); sb.AppendLine(); sb.AppendLine("To ovveride for remote access, add <diagnostics enableFor=\"allhosts\" /> in the <resizer> section of Web.config."); sb.AppendLine(); return(sb.ToString()); }
private Boolean CustomErrorTest() { Boolean isError = false; try { Configuration config = WebConfigurationManager.OpenWebConfiguration("~/web.config"); CustomErrorsSection section = (CustomErrorsSection)config.GetSection("system.web/customErrors"); CustomErrorsMode mode = section.Mode; hDefaultRedirect.Text = section.DefaultRedirect; hDefaultRedirect.NavigateUrl = section.DefaultRedirect; LCustomErrorsMode.Text = mode.ToString(); RCustomErrorCodes.DataSource = section.Errors; RCustomErrorCodes.DataBind(); if (mode == CustomErrorsMode.Off) { isError = true; } } catch (Exception ex) { isError = true; log.Error("Error checking custom error settings in web.config.", ex); } if (isError) { LCustomErrorStatus.Text = "Failed: Custom Errors are disabled in web.config, <br/>users may see unfriendly warnings or code details"; LCustomErrorStatus.CssClass = CSS_STATUS_ERROR; LCustomErrorsMode.CssClass = CSS_STATUS_WARN; } else { LCustomErrorStatus.Text = "Passed"; LCustomErrorStatus.CssClass = CSS_STATUS_NORMAL; LCustomErrorsMode.CssClass = CSS_PASS; } return(isError); }