Skip to content

Commit

Permalink
Make error response and actual 500 http status
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenbock committed Feb 3, 2017
1 parent 80de6d6 commit 2a7a451
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions AchmeErrorSite/AchmeErrorSite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@
<ItemGroup>
<Compile Include="AchmeClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SiteApplication.cs" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
Expand Down
2 changes: 1 addition & 1 deletion AchmeErrorSite/App_Data/Models/all.dll.path
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\75441ed1\d5440aaf\App_Web_all.generated.cs.8f9494c4.z-ucklgj.dll
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\75441ed1\d5440aaf\App_Web_all.generated.cs.8f9494c4.9mgasjtp.dll
Binary file modified AchmeErrorSite/App_Data/Umbraco.sdf
Binary file not shown.
2 changes: 1 addition & 1 deletion AchmeErrorSite/Global.asax
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<%@ Application Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>
<%@ Application Inherits="AchmeErrorSite.SiteApplication" Language="C#" %>

36 changes: 36 additions & 0 deletions AchmeErrorSite/SiteApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Web;
using Umbraco.Web;

namespace AchmeErrorSite
{
public class SiteApplication : UmbracoApplication
{
protected new void Application_Error(object sender, EventArgs e)
{
// This method is triggered twice when an exception occurs.
// Only do anything if there is actually an error.
// Otherwise just ignore it.

Exception lastError = Server.GetLastError();

if (lastError != null)
{
base.Application_Error(sender, e);
}

if (Context.IsCustomErrorEnabled)
{
if (lastError != null)
{
var httpException = lastError as HttpException ?? new HttpException(500, "Internal error");

var code = httpException.GetHttpCode();
Response.StatusCode = code;
Server.ClearError();
Server.Transfer("/500.html");
}
}
}
}
}
2 changes: 1 addition & 1 deletion AchmeErrorSite/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</system.net>

<system.web>
<customErrors mode="On" defaultRedirect="/500.html" redirectMode="ResponseRewrite" />
<customErrors mode="On" />
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<httpRuntime requestValidationMode="2.0" enableVersionHeader="false" targetFramework="4.5" maxRequestLength="51200" fcnMode="Single" />
<!--
Expand Down

0 comments on commit 2a7a451

Please sign in to comment.