Permalink
Browse files

404

  • Loading branch information...
kijanawoodard committed Nov 4, 2013
1 parent 0109d62 commit 48ed632e7045522e1404f1739dcc2cd982a63697
@@ -0,0 +1,13 @@
+using System.Web.Mvc;
+
+namespace Blog.Web.Actions.DisplayErrors
+{
+ public class DisplayErrorsController : Controller
+ {
+ public ActionResult Http404()
+ {
+ return View();
+ }
+
+ }
+}
@@ -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.
@@ -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">
@@ -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>
@@ -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;
@@ -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.