将 ASP.NET MVC 根应用程序路由到 MVC 虚拟目录
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
路线可能很棘手。在没有看到您的应用程序的情况下,我无法建议修复(有更多经验的人可能能够),但我可以建议安装 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.