Monday, April 23, 2012

How to implement proper HTTP error handling in .NET MVC 3?

I'm referring to Darin's answer in the following post.



I'm using MVC3 and I was wondering if this is still a way to handle errors?



In the rrror controller he has the following:



public ActionResult Http404()
{
Response.StatusCode = 404;

return Content("404", "text/plain");
}


Working from his code.. I want it to display the full URL, how would I do this? So it needs to be www.mywebsite.com/Error/Http404 and not just www.mywebsite.com. How would I do this? I thought that if I had the following code then it will display the full URL, but it still just displays www.mywebsite.com:



public ActionResult Http404()
{
Response.StatusCode = 404;

return View("Http404");
}


How would I get the value of ex that was set in the global.asax.cs to be displayed on this page?



I moved away from having my errors handled in the web.config because it kepted on have a aspxerrorpath in the querystring.





No comments:

Post a Comment