Skip to content

Commit

Permalink
404
Browse files Browse the repository at this point in the history
  • Loading branch information
kijanawoodard committed Nov 4, 2013
1 parent 0109d62 commit 48ed632
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Blog.Web/Actions/DisplayErrors/DisplayErrorsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Web.Mvc;

namespace Blog.Web.Actions.DisplayErrors
{
public class DisplayErrorsController : Controller
{
public ActionResult Http404()
{
return View();
}

}
}
10 changes: 10 additions & 0 deletions src/Blog.Web/Actions/DisplayErrors/Http404.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@model dynamic

@{
ViewBag.Title = "404";
Layout = "~/Views/_Layout.cshtml";
}

<h2>404</h2>

Hmmm. The page you're looking for seems to be missing.
4 changes: 4 additions & 0 deletions src/Blog.Web/Blog.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Actions\AtomGet\AtomGetController.cs" />
<Compile Include="Actions\DisplayErrors\DisplayErrorsController.cs" />
<Compile Include="Actions\PostGet\PostGetController.cs" />
<Compile Include="Infrastructure\AlternateViewEngine.cs" />
<Compile Include="Global.asax.cs">
Expand Down Expand Up @@ -270,6 +271,9 @@
<ItemGroup>
<Content Include="Content\posts\vessel-modules.markdown" />
</ItemGroup>
<ItemGroup>
<Content Include="Actions\DisplayErrors\Http404.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down
20 changes: 19 additions & 1 deletion src/Blog.Web/Global.asax.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Web.Mvc;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Blog.Web.Actions.DisplayErrors;
using Blog.Web.Infrastructure;
using Blog.Web.Initialization;

Expand All @@ -18,5 +20,21 @@ protected void Application_Start()
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new AlternateViewEngine());
}

//http://stackoverflow.com/a/9026907/214073
protected void Application_EndRequest()
{
if (Context.Response.StatusCode == 404)
{
Response.Clear();

var rd = new RouteData();
rd.Values["controller"] = "DisplayErrors";
rd.Values["action"] = "Http404";

IController c = new DisplayErrorsController();
c.Execute(new RequestContext(new HttpContextWrapper(Context), rd));
}
}
}
}

0 comments on commit 48ed632

Please sign in to comment.