Example #1
0
        /// <summary>
        ///     Generate XML
        /// </summary>
        /// <param name="context"></param>
        protected virtual void GenerateXml(PageGeneratorContext context)
        {
            var xml =
                string.Format(
                    @"<Error ReportId=""{0}"" hint=""Use the report id when contacting us if you need further assistance"">{1}</Error>",
                    context.ReportId, context.ReporterContext.ErrorMessage);

            context.SendResponse("application/xml", xml);
        }
Example #2
0
        /// <summary>
        ///     Generate JSON-based error page
        /// </summary>
        /// <param name="context"></param>
        protected virtual void GenerateJson(PageGeneratorContext context)
        {
            var json =
                string.Format(
                    @"{{""error"": {{ ""msg""=""{0}"", ""reportId""=""{1}""}}, hint=""Use the report id when contacting us if you need further assistance."" }}",
                    context.ReporterContext.ErrorMessage, context.ReportId);

            context.SendResponse("application/json", json);
        }
Example #3
0
        private void OnError(object sender, EventArgs e)
        {
            var app = (HttpApplication)sender;

            if (!ConfigExtensions.CatchExceptions)
                return;

            var exception = app.Server.GetLastError();
            var httpCodeIdentifier = new HttpCodeIdentifier(app, exception);

            var context = new HttpErrorReporterContext(this, exception)
            {
                HttpContext = app.Context,
                HttpStatusCode = httpCodeIdentifier.HttpCode,
                HttpStatusCodeName = httpCodeIdentifier.HttpCodeName,
                ErrorMessage = ExtractFirstLine(exception.Message)
            };
            var dto = OneTrue.GenerateReport(context);

            var collection =
                dto.ContextCollections.FirstOrDefault(
                    x => x.Name.Equals("ExceptionProperties", StringComparison.OrdinalIgnoreCase));
            if (collection != null)
            {
                if (!collection.Properties.ContainsKey("HttpCode"))
                    collection.Properties.Add("HttpCode", context.HttpStatusCode.ToString());
            }

            if (OneTrue.Configuration.UserInteraction.AskUserForPermission)
                TempData[dto.ReportId] = dto;
            else
                OneTrue.UploadReport(dto);

            app.Response.StatusCode = context.HttpStatusCode;
            app.Response.StatusDescription = context.ErrorMessage;
            app.Response.TrySkipIisCustomErrors = true;
            app.Response.ContentEncoding = Encoding.UTF8;

            var pageContext = new PageGeneratorContext
            {
                Request = new HttpRequestWrapper(app.Request),
                Response = new HttpResponseWrapper(app.Response),
                ReporterContext = context,
                ReportId = dto.ReportId
            };

            ConfigExtensions.ErrorPageGenerator.Generate(pageContext);
            app.Server.ClearError();
            app.Response.End();
        }
Example #4
0
        /// <summary>
        ///     Generate
        /// </summary>
        /// <param name="context">information about which page to generate</param>
        public void Generate(PageGeneratorContext context)
        {
            var htmlIndex = GetIndex(context.Request.AcceptTypes, "text/html");
            var jsonIndex = GetIndex(context.Request.AcceptTypes, "/json");
            var xmlIndex  = GetIndex(context.Request.AcceptTypes, "application/xml");

            if (jsonIndex < htmlIndex && jsonIndex < xmlIndex)
            {
                GenerateJson(context);
                return;
            }

            if (xmlIndex < htmlIndex)
            {
                GenerateXml(context);
                return;
            }

            GenerateHtml(context);
        }
Example #5
0
 /// <summary>
 ///     Generate HTML document
 /// </summary>
 /// <param name="context"></param>
 protected abstract void GenerateHtml(PageGeneratorContext context);