16. July 2014 07:57
/
Administrator
/
/
Comments (1)
While ASP.net MVC makes it easy and clean to create a professional looking website, it seems to be a little harder to incorporate custome error pages (e.g. 404 page) which are part of general look and feel of your site. There are many good write-ups on how to do this (for example http://benfoster.io/blog/aspnet-mvc-custom-error-pages), but I was looking for an easy way to point to one of my views as the 404 page.
What I ended up doing was to create a controller for my error views and use the httpErrors section of web.config to point to it:
As you can guess, "/Error/NotFound" points to my Controller and View for the 404 error. Controller code looks like this:
public class ErrorController : Controller
{
public ActionResult NotFound()
{
Response.StatusCode = 404;
return View();
}
}
212b3a36-bc23-4f1a-a23b-88160f72ab04|12|4.8|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags :