ASP.NET MVC - 在子目录中运行

发布于 2024-08-18 17:29:34 字数 759 浏览 7 评论 0原文

我正在尝试在现有应用程序的子目录中部署 ASP.NET MVC 应用程序,但遇到了一些路由问题。我已经设置了文件夹结构,以便 MVC 应用程序的所有二进制文件和配置文件都正确位于根目录中,而其余内容位于子目录中。此外,我更新了 MVC 应用程序中的所有路由以反映子目录;然而,对应用程序的每个请求都会产生:

传入的请求不匹配 任何路线。

所有定义的路由都被忽略,包括默认路由:

routes.MapRouteLowercase(
    "Main_Default",
    "blog/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

我尝试启用 RouteDebug 来测试问题,但即使如此也没有被路由到。关于我还可以尝试什么有什么建议吗?

注意:这个问题不是一个重复

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.MapRouteLowercase(
    "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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

前事休说 2024-08-25 17:29:34

尝试将其作为虚拟目录运行,而不仅仅是目录,否则您的路由将不会被调用。您不需要将虚拟目录的名称放入路由中。

这是我在 v-dir MVC 应用程序中设置的一条路线,效果很好......

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

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
);
海风掠过北极光 2024-08-25 17:29:34

看来我发现了问题。

除了二进制文件和配置文件之外,Global.asax 还必须放置在根目录中才能执行其代码。

谢谢你们。 :)

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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文