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

后端 未结 1 539

Folks,

I have been working on an MVC 3 app. I was using VS 2010\'s built-in web server. Today, for various reasons, I was asked to move it into a virtual director

相关标签:
1条回答
  • 2020-12-31 17:55

    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
    );
    
    0 讨论(0)
提交回复
热议问题