I'm trying to have 2 custom error pages in a stock sample ASP.NET MVC3 website.
Darin Dimitrov has a good SO answer here but it's not working for all my test conditions.
Then there is the widely popular How can I properly handle 404s in ASP.NET MVC? post .. but this just touches on a 404 error.
Can someone please explain what
- Routes
web.config
settings- controllers / action methods
are required to do this very simple thing :(
Scenarios to accept this answer:
- VS2010 -> File -> New -> ASP.NET MVC3 project / Internet Application
- (Right Click on the solution).. -> Use IIS Express
- Error pages cannot be a static html page. They must be a page which I can pass info to, like any other view, etc. (eg. an
ErrorController
)...
and for the test routes...
/Home/Index
-> shows index page/Home
-> shows index page/
-> shows index page/Home/About
-> shows about page/asdasd/asdsad/asdas/asddasd/adsad
-> 404/adsa/asda/asd/asd/asd/asd
-> 404/asdsadasda
-> 404
then add this to the HomeController.cs
class..
public ActionResult ThrowException()
{
throw new NotImplementedException();
}
and now ..
/home/throwexception
-> 500 error
Cheers :)
BTW, some of those realy long routes (above) give really weird error pages right now, when using the stock standard new ASP.NET MVC3
template