Dale Fraser
Dale Fraser

Reputation: 4758

URL obfuscation

I'm using ASP.NET with MVC4. In a simple controller I wish to use a URL such as

www.sitename.com/controller/action/param1/param2/param3

Can I do this?

The controller would be ControllerController and have a method

Action(param1, param2, param3)

etc

Upvotes: 1

Views: 490

Answers (1)

MarkG
MarkG

Reputation: 1869

Yes, just add a route such as:

routes.MapRoute(name: "MyRoute", url: "{controller}/{action}/{p1}/{p2}/{p3}");

If you want it for a specific controller then you can use "hard" names instead of the {controller} and {action} placeholders.

Make sure you add this before the more specific routes though (i.e. before the "Default" route).

You may also find the RouteDebugger on NuGet helpful.

Upvotes: 3

Related Questions