将 ASP.NET MVC 根应用程序路由到 MVC 虚拟目录

发布于 2024-12-05 20:14:31 字数 666 浏览 1 评论 0原文

我有一个 MVC 应用程序设置作为根应用程序。在该根目录中,我有一个虚拟目录,它也是一个 MVC 应用程序。我需要从根应用程序导航到虚拟目录。第一个障碍是找到存在于另一个命名空间中的控制器,我能够按如下方式执行此操作。

    Dim namespaceControllers() As String = {"ExternalAssemblyName"}

    routes.MapRoute( _
        "virtualroute", _
        "ExternalAssemblyName/{controller}/{action}/{id}", _
        New With {.controller = "testvir", .action = "Index", .id = ""}, _
        namespaceControllers _
    )

    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", .id = ""} _
    )

它正确地找到了控制器,但它仍然尝试在根应用程序中查找视图,而不是虚拟目录。如果我将视图从虚拟目录移动到根目录,它就可以工作。

I have an MVC application setup as a root application. With in that root dir I have a virtual directory that is also an MVC app. I need to navigate from the root app to the virtual directory. The first hurdle was finding the controller that existed in another namespace, and I was able to do that as follows..

    Dim namespaceControllers() As String = {"ExternalAssemblyName"}

    routes.MapRoute( _
        "virtualroute", _
        "ExternalAssemblyName/{controller}/{action}/{id}", _
        New With {.controller = "testvir", .action = "Index", .id = ""}, _
        namespaceControllers _
    )

    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", .id = ""} _
    )

It correctly finds the controller, however it still tried to locate the view in the root application, not the virtual dir. If I move the View from the virtual dir to the root dir, it works.

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

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

发布评论

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

评论(1

凉城凉梦凉人心 2024-12-12 20:14:31

路线可能很棘手。在没有看到您的应用程序的情况下,我无法建议修复(有更多经验的人可能能够),但我可以建议安装 RouteDebugger 工具帮助解决路由问题。它多次帮助我解决路由问题。

它还可以作为 NuGet 包提供。

Routes can be tricky. I can't recommend a fix without seeing your application (someone with more experience might be able to), but I can suggest installing the RouteDebugger tool to help with routing issues. It has helped me work out routing issues multiple times.

It's also available as a NuGet package.

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