开发者

ASP.NET MVC - Running in a Subdirectory

开发者 https://www.devze.com 2022-12-17 19:48 出处:网络
I am attempting to deploy an ASP.NET MVC application in a subdirectory of an existing application and I am running into some routing issues. I have set up the folder structure such that all of the bin

I am attempting to deploy an ASP.NET MVC application in a subdirectory of an existing application and I am running into some routing issues. I have set up the folder structure such that all of the binaries and config files for the MVC app are correctly located in the root directory, while the rest of the content is in the subdirectory. Additionally, I updated all of the routes in the MVC application to reflect the subdirectory; however, every request to the application produces:

The incoming request does not match any route.

All defined routes are being ignored, including the default route:

routes.MapRouteLow开发者_如何学编程ercase(
    "Main_Default",
    "blog/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

I tried enabling RouteDebug to test the issue, but even that is not getting routed to. Any advice on what else I can try?

Note: This question is not a duplicate.


Try running it as a virtual directory instead of just a directory, otherwise your routes are not going to be called. You will not need to put the name of the virtual directory in the route.

Here's a route that I have setup in a v-dir MVC app that works just fine...

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


Looks like I found the problem.

In addition to the binaries and the config files, Global.asax must also be placed in the root in order for its code to be executed.

Thanks guys. :)

0

精彩评论

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