开发者

When deploying an ASP.MVC 3 application to a subfolder (not root), how do I handle routes?

开发者 https://www.devze.com 2023-03-12 08:30 出处:网络
I\'m developing an ASP.MVC 3 project on my local computer where it is located at the root of t开发者_StackOverflow社区he local web server.

I'm developing an ASP.MVC 3 project on my local computer where it is located at the root of t开发者_StackOverflow社区he local web server.

localhost:12345/(project is here)

However, when I deploy to our public web server this application will be located in a subfolder

www.mycompany.com/myapp/(project goes here)

How do I deal with that mismatch? A few questions come to mind:

  1. Do I need to adjust my MVC routes? Or will they just capture anything after /myapp/ ?

  2. Do I use HomeController when I don't really want 'Home' to appear in the route? i.e. /myapp/home/(action)/(id) - rather I want this: /myapp/(action)/(id) if Home is the controller.

  3. Should I match this folder structure on my local machine? (This project will never have access to anything outside that 'myapp' folder)

  4. If 3 is yes, how?

I'm using VS 2010 with IIS Express locally.


  1. The routes are relative to the web application. Which means that you don't need to have /myapp/ in your routes.
  2. No you don't need to have Home appear in the route. Personally as a practice I take out the default route.
  3. No you don't need to match this folder structure.


In our experience I found that within the Controllers there is no problem with the routes.

However, if you use HTML helpers within your views, like Html.BeginForm or Html.Action, these do not work with the overloaded methods that receive controller, action arguments. You need to put the whole Url in the Html helpers using Url.Content,

This does not work:

Html.BeginForm()

or

Html.BeginForm("ResetPassword", "Account")

But this works:

Html.BeginForm(Url.Content("~/Account/ResetPassword");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号