ASP.NET MVC 当应用程序作为域的子项目发布时如何使用路由?

发布于 2024-07-17 12:41:47 字数 1016 浏览 5 评论 0原文

我有一个网络应用程序,在本地调试和测试时可以完美运行。 但是,当我将站点发布到生产服务器时,路由就混乱了。 这是因为它作为生产服务器上的子项目运行。

Testing:     http://localhost:xxx/
Production:  http://remotehost/webapp/

我应该如何设置路由?

这是我当前的路由设置(大部分是默认的)。 当我访问 http://remotehost/webapp/ 时,服务器显示默认的控制器操作。 但是当我对控制器进行硬编码时(http://remotehost/webapp/Project/ 它不会工作...

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

    routes.MapRoute("ProjectsByCategory", "Project/Category/{id}", _
                    New With {.controller = "Project", .action = "ListByCategory", .id = ""}, _
                    New With {.id = "^[0-9]+"})


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

End Sub

i have a webapp which works perfectly when debugged and tested locally. However when I publish the site to a productionserver the routing is messed up. This is because it runs as a sub-project on the productionserver.

Testing:     http://localhost:xxx/
Production:  http://remotehost/webapp/

How should I setup routing?

This is my current routing setup (mostly default). The server displays the default Controller action when I visit http://remotehost/webapp/. But when I hard-code the controller (http://remotehost/webapp/Project/ it doesn't work...

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

    routes.MapRoute("ProjectsByCategory", "Project/Category/{id}", _
                    New With {.controller = "Project", .action = "ListByCategory", .id = ""}, _
                    New With {.id = "^[0-9]+"})


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

End Sub

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

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

发布评论

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

评论(2

凹づ凸ル 2024-07-24 12:41:47

对我来说,这听起来可能与在 iis 6 上发布有关。有一篇文章 此处 关于这一点。

对我来说,通过添加“通配符应用程序映射”解决了类似的问题:

  • 在 IIS 中,右键单击并选择相关虚拟目录的“属性”,
  • 选择“虚拟目录”选项卡,
  • 选择“配置”
  • ,单击“插入”,
  • 输入 aspnet-isapi.dll 的路径(通常为 c) :\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll)。

To me it sounds like it might be related to publishing on iis 6. There's an article here about that.

For me a similar problem was resolved by adding a 'Wildcard application map':

  • In IIS, right click and choose Properties for the virtual directory in question
  • choose Virtual directory tab
  • choose Configuration
  • click Insert
  • enter the path to aspnet-isapi.dll (typically c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll).
楠木可依 2024-07-24 12:41:47

顺便说一下,路由似乎在应用程序级别上工作。 无需打扰您的域名或更高的目录名称。

By the way, the routing seems to be working on application level. No need to bother your domainname or higher directory names.

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