Custom Error Handling

This commit is contained in:
Gary Sharp
2013-11-11 17:04:04 +11:00
parent a63041abf2
commit 1cbbf1dde4
12 changed files with 296 additions and 49 deletions
+2 -23
View File
@@ -1,6 +1,7 @@
using Disco.Data.Repository;
using Disco.Services.Authorization;
using Disco.Services.Users;
using Disco.Services.Web;
using System;
using System.Configuration;
using System.Diagnostics;
@@ -214,29 +215,7 @@ namespace Disco.Web
#region Global Error Logging
void DiscoApplication_Error(object sender, EventArgs e)
{
try
{
var ex = Server.GetLastError();
if (ex is AccessDeniedException)
{
var accessDeniedException = (AccessDeniedException)ex;
var resource = accessDeniedException.Resource;
var httpContext = HttpContext.Current;
if (httpContext != null && httpContext.Request != null)
resource = string.Format("{0} [{1}]", resource, httpContext.Request.RawUrl);
AuthorizationLog.LogAccessDenied(UserService.CurrentUserId ?? "[Anonymous]", resource, accessDeniedException.Message);
}
else
{
Disco.Services.Logging.SystemLog.LogException("Global Application Exception Caught", ex);
}
}
catch (Exception)
{
// Ignore all logging errors
}
this.HandleException();
}
#endregion
}
+35 -7
View File
@@ -1,10 +1,38 @@
@model System.Web.Mvc.HandleErrorInfo
@{
ViewBag.Title = "Error";
}
ViewBag.Title = "Server Error";
<hgroup class="title">
<h1 class="error">Error.</h1>
<h2 class="error">An error occurred while processing your request.</h2>
</hgroup>
var ex = Model.Exception;
while (ex != null)
{
<div class="form" style="width: 650px">
<h2 style="white-space: pre;">@ex.Message</h2>
<table style="background-color: #fff;">
<tr>
<th style="width: 40px;">Type:</th>
<td>
@ex.GetType().Name
</td>
</tr>
<tr>
<th>Stack:
</th>
<td>
<div class="code" style="width: 560px; white-space: pre; overflow: auto;">@ex.StackTrace</div>
</td>
</tr>
</table>
</div>
ex = ex.InnerException;
}
}
<script>
$(function () {
$('#layout_PageHeading').css({ 'background': '#C80000', 'color': '#fff' });
$('#layout_Page').css({ 'background': 'linear-gradient(to top, #F2B0B0, #C80000 200px)' }).find('h2').css({ 'color': '#fff' });
});
</script>
+77 -10
View File
@@ -2,7 +2,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18051
// Runtime Version:4.0.30319.34003
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -43,26 +43,93 @@ namespace Disco.Web.Views.Shared
public override void Execute()
{
#line 3 "..\..\Views\Shared\Error.cshtml"
#line 2 "..\..\Views\Shared\Error.cshtml"
ViewBag.Title = "Error";
ViewBag.Title = "Server Error";
var ex = Model.Exception;
while (ex != null)
{
#line default
#line hidden
WriteLiteral("\r\n\r\n<hgroup");
WriteLiteral(" <div");
WriteLiteral(" class=\"title\"");
WriteLiteral(" class=\"form\"");
WriteLiteral(">\r\n <h1");
WriteLiteral(" style=\"width: 650px\"");
WriteLiteral(" class=\"error\"");
WriteLiteral(">\r\n <h2");
WriteLiteral(">Error.</h1>\r\n <h2");
WriteLiteral(" style=\"white-space: pre;\"");
WriteLiteral(" class=\"error\"");
WriteLiteral(">");
WriteLiteral(">An error occurred while processing your request.</h2>\r\n</hgroup>\r\n");
#line 12 "..\..\Views\Shared\Error.cshtml"
Write(ex.Message);
#line default
#line hidden
WriteLiteral("</h2>\r\n <table");
WriteLiteral(" style=\"background-color: #fff;\"");
WriteLiteral(">\r\n <tr>\r\n <th");
WriteLiteral(" style=\"width: 40px;\"");
WriteLiteral(">Type:</th>\r\n <td>\r\n");
WriteLiteral(" ");
#line 17 "..\..\Views\Shared\Error.cshtml"
Write(ex.GetType().Name);
#line default
#line hidden
WriteLiteral("\r\n </td>\r\n </tr>\r\n <tr>\r\n <th" +
">Stack:\r\n </th>\r\n <td>\r\n <div");
WriteLiteral(" class=\"code\"");
WriteLiteral(" style=\"width: 560px; white-space: pre; overflow: auto;\"");
WriteLiteral(">");
#line 24 "..\..\Views\Shared\Error.cshtml"
Write(ex.StackTrace);
#line default
#line hidden
WriteLiteral("</div>\r\n </td>\r\n </tr>\r\n </table>\r\n </div>\r\n");
#line 29 "..\..\Views\Shared\Error.cshtml"
ex = ex.InnerException;
}
#line default
#line hidden
WriteLiteral(@"
<script>
$(function () {
$('#layout_PageHeading').css({ 'background': '#C80000', 'color': '#fff' });
$('#layout_Page').css({ 'background': 'linear-gradient(to top, #F2B0B0, #C80000 200px)' }).find('h2').css({ 'color': '#fff' });
});
</script>
");
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
</compilation>
<httpRuntime targetFramework="4.5" />
<authentication mode="Windows" />
<customErrors mode="Off" />
<customErrors mode="On" />
<pages controlRenderingCompatibilityVersion="4.0">
<namespaces>
<add namespace="System.Web.Helpers" />