Beispiel #1
0
        /// <summary>
        /// An error have occurred and we need to send a result pack to the client
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="exception">The exception.</param>
        /// <remarks>
        /// Invoke base class (<see cref="Server"/>) to send the contents
        /// of <see cref="IHttpContext.Response"/>.
        /// </remarks>
        protected virtual void DisplayErrorPage(IHttpContext context, Exception exception)
        {
            var httpException = exception as HttpException;

            if (httpException != null)
            {
                context.Response.Reason = httpException.Code.ToString();
                context.Response.Status = httpException.Code;
            }
            else
            {
                context.Response.Reason = "Internal Server Error";
                context.Response.Status = HttpStatusCode.InternalServerError;
            }


            var args = new ErrorPageEventArgs(context)
            {
                Exception = exception
            };

            ErrorPageRequested(this, args);

            var writer = HttpFactory.Current.Get <ResponseWriter>();

            if (args.IsHandled)
            {
                writer.Send(context, context.Response);
            }
            else
            {
                writer.SendErrorPage(context, context.Response, exception);
                args.IsHandled = true;
            }
        }
Beispiel #2
0
        private void SendErrorPage(Exception exception)
        {
            var httpException = exception as HttpException;
            var response      = HttpContext.Current.Response;

            response.Status = httpException != null ? httpException.Code : HttpStatusCode.InternalServerError;
            response.Reason = exception.Message;

            if (response.Body.CanWrite)
            {
                response.Body.SetLength(0);
            }

            var args = new ErrorPageEventArgs(HttpContext.Current)
            {
                Exception = exception
            };

            ErrorPageRequested(this, args);

            try
            {
                var generator = new ResponseWriter();
                if (args.IsHandled)
                {
                    generator.Send(HttpContext.Current, response);
                }
                else
                {
                    generator.SendErrorPage(HttpContext.Current, response, exception);
                }
            }
            catch (Exception err)
            {
                _logger.Error("Failed to display error page", err);
            }
        }
Beispiel #3
0
 private void Listener_OnErrorPage(object sender, ErrorPageEventArgs e)
 {
     _server = this;
     DisplayErrorPage(e.Context, e.Exception);
     e.IsHandled = true;
 }