I want to use a custom route in my global.asax with response.redirecttoroute but it is not working. I have the following in my RouteConfig:
routes.MapRoute(
name: "Error",
url: "Error/{action}/{excep}",
defaults: new { action = "Index", excep = UrlParameter.Optional }
);
And in my global.asax I do the following:
Response.RedirectToRoute("Error", new { action="Index", excep=ex.Message });
In my ErrorController I have:
public ActionResult Index(string excep)
{
ViewBag.Exception = excep;
return View();
}
And in my Index view for the error I call the ViewBag.Exception to show the exception.
When I use:
Response.Redirect("/Error/Index/0/"+ex.Message, true);
And use this in my controller:
public ActionResult Index(int? id,string excep)
{
ViewBag.Exception = excep;
return View();
}
It works, but this is with the default route and is not what I want. Why does it work with a redirect but not with redirecttoroute?