very simple question but I couldn’t find an answer for this:
I have the default {controller}/{action}/{id} pattern in my global.asax.
I need also something will give me something like http://www.example.com/microsoft or http://www.example.com/apple while Microsoft and apple are id stored in database. Using the default pattern would be: http://www.example.com/brands/detail/microsoft
any idea how the pattern should be?
i tried: {id} and set the controller and action to brands and detail it work to serve my need but ruins all others pattern.
thanks
Your route order matters. So create a first route definition which handles all available controllers and then mention one which will handle the rest of the requests. There you will handle the
www.yousite.com/applekind of requestNow create a new class called
FromValuesListContraintwhich inherit from IRouteConstraintHave your
Profileaction method in Home read the parameter value and get data from your database.So whenever a request comes, It will check whether it is a controller available ( which you passed into the FromValuesListContraint class constructor in your first route definition), if available then it will go for that routing, else, it will go for the general (default) route mentioned as the second route.
In this example, Home, Account and OtherOnes are my available controllers. whenever you add a new controller to your project, you want to add that to the constrctor of FromValuesListConstraint class constructor.
Simply saying it works like Catching some specific exception and going to the general exception if none of them are caught! 🙂 (just an example to understand)