Does anyone know how to get the current RequestContext from the Application_Error event in global.asax?? My problem is that i need to do a redirect, and thereby need to have the url generated using UrlHelper - which takes the aformentioned RequestContext.
A:
HttpContext.Current ?
EDIT: Sorry I did not notice you tagged it with MVC. I don't know in that case...
Rashack
2009-03-30 11:07:26
Either way that does not give you a RequestContext - it gives you the HttpContext, which is not the same.
Christian Nielsen
2009-03-30 11:17:31
+3
A:
While there is no direct way of accessing the RequestContext, you can create one yourself:
RequestContext context = new RequestContext(new HttpContextWrapper(HttpContext.Current), RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current)))
So the UrlHelper can be constructed via:
UrlHelper helper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current))));
Not pretty, but it gets the job done.
Gene Hallman
2009-12-18 00:08:39