Browse Source

Made error pages actually return the correct status codes.

master
Teknikode 6 years ago
parent
commit
af77b43890
  1. 1
      Teknik/App_Start/RouteConfig.cs
  2. 29
      Teknik/Areas/Error/Controllers/ErrorController.cs
  3. 1
      Teknik/Web.config

1
Teknik/App_Start/RouteConfig.cs

@ -15,7 +15,6 @@ namespace Teknik @@ -15,7 +15,6 @@ namespace Teknik
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = ".*/favicon\\.ico" });
}
}
}

29
Teknik/Areas/Error/Controllers/ErrorController.cs

@ -19,7 +19,10 @@ namespace Teknik.Areas.Error.Controllers @@ -19,7 +19,10 @@ namespace Teknik.Areas.Error.Controllers
ViewBag.Description = "Just a boring 'ol exception. Nothing to see here, move along.";
if (Response != null)
Response.StatusCode = 200;
{
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;
}
ErrorViewModel model = new ErrorViewModel();
model.Exception = exception;
@ -34,6 +37,12 @@ namespace Teknik.Areas.Error.Controllers @@ -34,6 +37,12 @@ namespace Teknik.Areas.Error.Controllers
ViewBag.Title = "Http Exception - " + Config.Title;
ViewBag.Description = "There has been a Http exception. Run!";
if (Response != null)
{
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;
}
ErrorViewModel model = new ErrorViewModel();
model.Description = exception.Message;
model.Exception = exception;
@ -48,6 +57,12 @@ namespace Teknik.Areas.Error.Controllers @@ -48,6 +57,12 @@ namespace Teknik.Areas.Error.Controllers
ViewBag.Title = "403 - " + Config.Title;
ViewBag.Description = "Access Denied";
if (Response != null)
{
Response.StatusCode = 403;
Response.TrySkipIisCustomErrors = true;
}
ErrorViewModel model = new ErrorViewModel();
model.Exception = exception;
@ -61,6 +76,12 @@ namespace Teknik.Areas.Error.Controllers @@ -61,6 +76,12 @@ namespace Teknik.Areas.Error.Controllers
ViewBag.Title = "404 - " + Config.Title;
ViewBag.Description = "Uh Oh, can't find it!";
if (Response != null)
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
}
ErrorViewModel model = new ErrorViewModel();
model.Exception = exception;
@ -74,6 +95,12 @@ namespace Teknik.Areas.Error.Controllers @@ -74,6 +95,12 @@ namespace Teknik.Areas.Error.Controllers
ViewBag.Title = "500 - " + Config.Title;
ViewBag.Description = "Something Borked";
if (Response != null)
{
Response.StatusCode = 500;
Response.TrySkipIisCustomErrors = true;
}
ErrorViewModel model = new ErrorViewModel();
model.Exception = exception;

1
Teknik/Web.config

@ -52,6 +52,7 @@ @@ -52,6 +52,7 @@
<add name="strict-transport-security" value="max-age=31536000; includeSubdomains" />
</customHeaders>
</httpProtocol>
<httpErrors errorMode="Detailed" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Loading…
Cancel
Save