In my web.config file I have customErrors on and default redirect to my controller ErrorController like so:
<customErrors mode="On" defaultRedirect="/Error/">
</customErrors>
What I am trying do now in my Index method of my ErrorController is get the error code (404, 405, etc), I have tried the following:
public class ErrorController : Controller
{
public ActionResult Index()
{
ViewBag.statusCode = System.Web.HttpContext.Current.Response.StatusCode;
return View();
}
}
But it always returns 200 because its redirecting to a page with the status code 200....When I goto a page that does not exists, I still get a 200 code instead of 404. I just want to have one page, get the error code instead of having multiple error pages. Is this possible?