MetaGuru
MetaGuru

Reputation: 43863

Is there a way to make MVC.NET routing ignore a few /dir/paths/?

Meaning I could have the URL routing start at like site.com/v3/site/controller/action

basically it would ignore the v3/site/ and treat that as root?

Upvotes: 1

Views: 299

Answers (2)

Darko
Darko

Reputation: 38880

You sure can. Check out the following routes:

routes.MapRoute("Route1", "StaticFolder/{name}/{id}", new { controller = "Controller1", action = "Action1", name = "Sample", id = "1" });

Route 1 will always invoke Action1 on Controller1 on any requests for resources in StaticFolder.

routes.MapRoute("Route2", "StaticFolder1/{id}/{action}", new { controller = "Controller2", action = "Action2", id = "1" });

Route 2 will always invoke Controller2 with specified action (defaulting to Action2) for any requests to StaticFolder1.

In your case specifically though you want to remove the default route and replace it with the following:

routes.MapRoute("Default", "/v3/site/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" });

Upvotes: 3

statenjason
statenjason

Reputation: 5190

It sounds like the the application root is at /v3/site. As far as I know, ASP-MVC's routing can't intercept routes below its own root (would likely be a security issue). Seems more like an IIS configuration that's needed than an MVC routing rule.

Upvotes: 0

Related Questions