views:

124

answers:

1

I'm trying to instantiate a service and authenticate the current user within the Application_PreRequestHandlerExecute() method and then dispose of this service in the* Application_PostRequestHandlerExecute() method of the global.asax.cs class. One of the items I need for this process is the orgname which is appended at the beginning of my url route. I have mapped a route that looks like this "{orgName}/{controller}/{action}/{id}"

So my question is, within an ASP.Net MVC application is it possible to access any of the routing information (or somehow access the "orgname" in my instance) within the Application_PreRequestHandlerExecute() event? If this is not possible is there some other way to hook into an MvcHandler and do something similar (maybe I should build a custom filter?)

+1  A: 

You need the "RequestContext" to find all the route values. I don't know any other way to get them than inside the controller.

You sould implement a "ActionFilterAttribute", then decorate your controllers with it.

the ActionFilter has the methods

//     Called after the action method executes.
public virtual void OnActionExecuted(ActionExecutedContext filterContext);
//     Called before the action method executes.
public virtual void OnActionExecuting(ActionExecutingContext filterContext);

that you can do all sorts of fun stuff in.

AndreasN