ASP.NET MVC 当应用程序作为域的子项目发布时如何使用路由?
我有一个网络应用程序,在本地调试和测试时可以完美运行。 但是,当我将站点发布到生产服务器时,路由就混乱了。 这是因为它作为生产服务器上的子项目运行。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说,这听起来可能与在 iis 6 上发布有关。有一篇文章 此处 关于这一点。
对我来说,通过添加“通配符应用程序映射”解决了类似的问题:
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':
顺便说一下,路由似乎在应用程序级别上工作。 无需打扰您的域名或更高的目录名称。
By the way, the routing seems to be working on application level. No need to bother your domainname or higher directory names.