// Return error message in markup using adaptive rendering of web
        // controls.  This would also set the corresponding headers of the
        // response accordingly so content can be shown properly on devices.
        // This method has been added with the same signature of
        // GetHtmlErrorMessage for consistency.
        internal virtual string GetAdaptiveErrorMessage(HttpContext context, bool dontShowSensitiveInfo) {

            // This call will compute and set all the necessary properties of
            // this instance of ErrorFormatter.  Then the controls below can
            // collect info from the properties.  The returned html is safely
            // ignored.
            GetHtmlErrorMessage(dontShowSensitiveInfo);

            // We need to inform the Response object that adaptive error is used
            // so it can adjust the status code right before headers are written out.
            // It is because some mobile devices/browsers can display a page
            // content only if it is a normal response instead of response that
            // has error status code.
            context.Response.UseAdaptiveError = true;

            try {
                Page page = new ErrorFormatterPage();
                page.EnableViewState = false;

                HtmlForm form = new HtmlForm();
                page.Controls.Add(form);
                IParserAccessor formAdd = (IParserAccessor) form;

                // Display a server error text with the application name
                Label label = CreateLabelFromText(SR.GetString(SR.Error_Formatter_ASPNET_Error, HttpRuntime.AppDomainAppVirtualPath));
                label.ForeColor = Color.Red;
                label.Font.Bold = true;
                label.Font.Size = FontUnit.Large;
                formAdd.AddParsedSubObject(label);
                formAdd.AddParsedSubObject(CreateBreakLiteral());

                // Title
                label = CreateLabelFromText(ErrorTitle);
                label.ForeColor = Color.Maroon;
                label.Font.Bold = true;
                label.Font.Italic = true;
                formAdd.AddParsedSubObject(label);
                formAdd.AddParsedSubObject(CreateBreakLiteral());

                // Description
                formAdd.AddParsedSubObject(CreateLabelFromText(SR.GetString(SR.Error_Formatter_Description) + " " + Description));
                formAdd.AddParsedSubObject(CreateBreakLiteral());

                // Misc Title
                String miscTitle = MiscSectionTitle;
                if (!String.IsNullOrEmpty(miscTitle)) {
                    formAdd.AddParsedSubObject(CreateLabelFromText(miscTitle));
                    formAdd.AddParsedSubObject(CreateBreakLiteral());
                }

                // Misc Info
                StringCollection miscContent = AdaptiveMiscContent;
                if (miscContent != null && miscContent.Count > 0) {
                    foreach (String contentLine in miscContent) {
                        formAdd.AddParsedSubObject(CreateLabelFromText(contentLine));
                        formAdd.AddParsedSubObject(CreateBreakLiteral());
                    }
                }

                // File & line# info
                String sourceFilePath = GetDisplayPath();
                if (!String.IsNullOrEmpty(sourceFilePath)) {
                    String text = SR.GetString(SR.Error_Formatter_Source_File) + " " + sourceFilePath;
                    formAdd.AddParsedSubObject(CreateLabelFromText(text));
                    formAdd.AddParsedSubObject(CreateBreakLiteral());

                    text = SR.GetString(SR.Error_Formatter_Line) + " " + SourceFileLineNumber;
                    formAdd.AddParsedSubObject(CreateLabelFromText(text));
                    formAdd.AddParsedSubObject(CreateBreakLiteral());
                }

                // Stack trace info
                StringCollection stackTrace = AdaptiveStackTrace;
                if (stackTrace != null && stackTrace.Count > 0) {
                    foreach (String stack in stackTrace) {
                        formAdd.AddParsedSubObject(CreateLabelFromText(stack));
                        formAdd.AddParsedSubObject(CreateBreakLiteral());
                    }
                }

                // Temporarily use a string writer to capture the output and
                // return it accordingly.
                StringWriter stringWriter = new StringWriter(CultureInfo.CurrentCulture);
                TextWriter textWriter = context.Response.SwitchWriter(stringWriter);
                page.ProcessRequest(context);
                context.Response.SwitchWriter(textWriter);

                return stringWriter.ToString();
            }
            catch {
                return GetStaticErrorMessage(context);
            }
        }
 internal virtual string GetAdaptiveErrorMessage(HttpContext context, bool dontShowSensitiveInfo)
 {
     this.GetHtmlErrorMessage(dontShowSensitiveInfo);
     context.Response.UseAdaptiveError = true;
     try
     {
         Page page = new ErrorFormatterPage {
             EnableViewState = false
         };
         HtmlForm child = new HtmlForm();
         page.Controls.Add(child);
         IParserAccessor accessor = child;
         Label label = this.CreateLabelFromText(System.Web.SR.GetString("Error_Formatter_ASPNET_Error", new object[] { HttpRuntime.AppDomainAppVirtualPath }));
         label.ForeColor = Color.Red;
         label.Font.Bold = true;
         label.Font.Size = FontUnit.Large;
         accessor.AddParsedSubObject(label);
         accessor.AddParsedSubObject(this.CreateBreakLiteral());
         label = this.CreateLabelFromText(this.ErrorTitle);
         label.ForeColor = Color.Maroon;
         label.Font.Bold = true;
         label.Font.Italic = true;
         accessor.AddParsedSubObject(label);
         accessor.AddParsedSubObject(this.CreateBreakLiteral());
         accessor.AddParsedSubObject(this.CreateLabelFromText(System.Web.SR.GetString("Error_Formatter_Description") + " " + this.Description));
         accessor.AddParsedSubObject(this.CreateBreakLiteral());
         string miscSectionTitle = this.MiscSectionTitle;
         if (!string.IsNullOrEmpty(miscSectionTitle))
         {
             accessor.AddParsedSubObject(this.CreateLabelFromText(miscSectionTitle));
             accessor.AddParsedSubObject(this.CreateBreakLiteral());
         }
         StringCollection adaptiveMiscContent = this.AdaptiveMiscContent;
         if ((adaptiveMiscContent != null) && (adaptiveMiscContent.Count > 0))
         {
             foreach (string str2 in adaptiveMiscContent)
             {
                 accessor.AddParsedSubObject(this.CreateLabelFromText(str2));
                 accessor.AddParsedSubObject(this.CreateBreakLiteral());
             }
         }
         string displayPath = this.GetDisplayPath();
         if (!string.IsNullOrEmpty(displayPath))
         {
             string text = System.Web.SR.GetString("Error_Formatter_Source_File") + " " + displayPath;
             accessor.AddParsedSubObject(this.CreateLabelFromText(text));
             accessor.AddParsedSubObject(this.CreateBreakLiteral());
             text = System.Web.SR.GetString("Error_Formatter_Line") + " " + this.SourceFileLineNumber;
             accessor.AddParsedSubObject(this.CreateLabelFromText(text));
             accessor.AddParsedSubObject(this.CreateBreakLiteral());
         }
         StringCollection adaptiveStackTrace = this.AdaptiveStackTrace;
         if ((adaptiveStackTrace != null) && (adaptiveStackTrace.Count > 0))
         {
             foreach (string str5 in adaptiveStackTrace)
             {
                 accessor.AddParsedSubObject(this.CreateLabelFromText(str5));
                 accessor.AddParsedSubObject(this.CreateBreakLiteral());
             }
         }
         StringWriter writer = new StringWriter(CultureInfo.CurrentCulture);
         TextWriter writer2 = context.Response.SwitchWriter(writer);
         page.ProcessRequest(context);
         context.Response.SwitchWriter(writer2);
         return writer.ToString();
     }
     catch
     {
         return this.GetStaticErrorMessage(context);
     }
 }