1



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.

1 Answer 1

3

This should work

 routes.MapRoute("Fixed", "abc/def", new { controller = "Sugar", action = "def"});
Sign up to request clarification or add additional context in comments.

2 Comments

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.
Yeah, since this is a more specific route it needs to come before the default routes. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.