Exemplo n.º 1
0
 /// <summary>
 /// Sharad 20 Oct 2012: For AJAX requests, the yellow screen is unreadable. This attribute returns exception content instead of the HTML content of the yellow screen.
 /// Also raises error event
 /// </summary>
 /// <remarks>
 /// <code>
 /// <![CDATA[
 /// $.ajax({
 ///
 ///   error: function(
 ///
 /// });
 ///
 ///
 ///
 /// ]]>
 /// </code>
 /// </remarks>
 protected override void OnException(ExceptionContext filterContext)
 {
     if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest() && !filterContext.ExceptionHandled)
     {
         filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         filterContext.Result = new ContentResult {
             Content = filterContext.Exception.Message
         };
         filterContext.ExceptionHandled = true;
         // Sharad 24 Mar 2014: Logging the exception
         this.HttpContext.Trace.Warn("AjaxException", "Exception encountered in AJAX request", filterContext.Exception);
     }
     else
     {
         // Default handling
         base.OnException(filterContext);
     }
     if (filterContext.ExceptionHandled)
     {
         // Log exceptions which occurred but were internally handled, such as our AJAX request exception
         var ev = new MvcErrorEvent("EclipseController.OnException log of handled exception", this, filterContext.Exception);
         ev.Raise();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Sharad 20 Oct 2012: For AJAX requests, the yellow screen is unreadable. This attribute returns exception content instead of the HTML content of the yellow screen.
 /// Also raises error event
 /// </summary>
 /// <remarks>
 /// <code>
 /// <![CDATA[
 /// $.ajax({
 /// 
 ///   error: function(
 /// 
 /// });
 /// 
 /// 
 /// 
 /// ]]>
 /// </code>
 /// </remarks>
 protected override void OnException(ExceptionContext filterContext)
 {
     if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest() && !filterContext.ExceptionHandled)
     {
         filterContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         filterContext.Result = new ContentResult { Content = filterContext.Exception.Message };
         filterContext.ExceptionHandled = true;
         // Sharad 24 Mar 2014: Logging the exception
         this.HttpContext.Trace.Warn("AjaxException", "Exception encountered in AJAX request", filterContext.Exception);
     }
     else
     {
         // Default handling
         base.OnException(filterContext);
     }
     if (filterContext.ExceptionHandled)
     {
         // Log exceptions which occurred but were internally handled, such as our AJAX request exception
         var ev = new MvcErrorEvent("EclipseController.OnException log of handled exception", this, filterContext.Exception);
         ev.Raise();
     }
 }