ASP.NET MVC 3: Moved app into virtual directory. What do I have to change?

放肆的年华 提交于 2019-12-03 07:23:12

In IIS, choose your virtual directory and "Convert to Application." Also, if you are using the default route map in your Global.asax it should read something like this:

routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Reasoning: If you put your MVC application in a sub-directory of another application then IIS will consider the root of that other application instead of the root of your MVC application. If that is the behavior that you want (unlikely) then you need to modify your Global.asax to take that into account:

routes.MapRoute(
    "Default", // Route name
    "MyVirtualDirectory/{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!