I want to run a certain Asp.NET MVC 4 Controller when an URL -probably irrelevant with the controller name- is entered. For example, if the user opens the address "localhost:3364/abc/def", I want to run the controller with the name, for example, "SugarController". Is it possible, or do I have to start my URL with the word "Sugar"? I know that URL routing can be done by adding some code to Global.asax file in the project. But I don't exactly know how to manage this one.
Thanks in advance.
Add a comment
|
1 Answer
This should work
routes.MapRoute("Fixed", "abc/def", new { controller = "Sugar", action = "def"});
2 Comments
moztemur
I had tried this but I had not been able to manage. When I put url routing stuff at the beginning of the Application_Start() method inside Global.asax before default register operations that Visual Studio puts inside the same method, this has worked. Before, I had put url routing code after these operations. I don't exactly know why this happens :) Thank you since you make me sure that this should work.
bmavity
Yeah, since this is a more specific route it needs to come before the default routes. :)