Dylan Czenski
Dylan Czenski

Reputation: 1365

Add a sub-routeunder the root but over all the controllers

I have an ASP.NET MVC web application with the following routing system:

localhost:20119

And I want to modify it so that there is one more subroute/directory that "contains" all of the routes, such as:

localhost:20119

So instead of going to the following URL:

http://localhost:20119/Home/Index

Users will instead go to

http://localhost:20119/AppName/Home/Index

I am using:

and I believe MVC 4:

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>

These are my configurations: enter image description here

Upvotes: 0

Views: 65

Answers (2)

NightOwl888
NightOwl888

Reputation: 56869

If you want to bind the routing scheme to a physical directory location, there is an open source project that does just that called MvcCodeRouting (available on NuGet). There is nothing built into MVC that correlates routes with a physical directory location, but MVC can be extended to do it as in that project.

Upvotes: 0

Bacskay
Bacskay

Reputation: 406

You should just be able to add another layer to the routes in RouteConfig.cs. For example, you could do something like:

routes.MapRoute(
  name: "Default",
  url: "AppName/{controller}/{action}",
  defaults: new { controller = "Home", action = "Index" }
);

Upvotes: 2

Related Questions