views:

322

answers:

1

How to assign controller name and action name dynamically in asp.net mvc

+1  A: 

On HttpApplication.Application_Start your can add dynamically any routes (Controller and Action anme) to RouteTable.Routes, this you can use any information available in this event or ever populate routes from config file or database.
For example

new Route( "Admin/{actionName}/{slug}/", CreateRouteHandler())  
{  
   Defaults = new RouteValueDictionary(defaults),  
   Url = new RouteValueDictionary(dataTokens)  
}

You couldn't change actions in RouteHandler, you could process current HttpRequest in your different ways, for example.

pocheptsov