简体   繁体   中英

MVC Routing Inside a Folder

I have built a standard MVC application with controllers and views and the following routes:-

routes.MapRoute
(
  name: "PageNumber",
  url: "{controller}/{action}/page-{pageNumber}",
  defaults: new { controller = "Home", action = "PageNumber" }
);
routes.MapRoute
(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);

Because this a back-end system, there will be a basic HTML website on the front of this. It means I need to route my site into a subfolder, so that the URL's look like this:-

SubFolder/Controller/Action/{id}

How can I do this, without changing all of my hard-coded links to include this sub-folder. I can't use MVC Areas for this, so was wondering if there was a way of changing the routing to automatically pre-pend the SubFolder bit of the URL?

Thanks!

You could make a new route:

 routes.MapRoute(
            name: "Subfolder",
            url: "Subfolder/{controller}/{action}/{id}",
            defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
        );

However you should not be hard coding links, if you have future plans to replace the basic HTML page you could use @Html.ActionLink to generate the anchor tags for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM