基于域&的ASP.NET MVC路由主机名 [英] ASP.NET MVC Routing based on domain & hostname
本文介绍了基于域&的ASP.NET MVC路由主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 ASP.NET MVC 的新手,我的大部分经验都在 ASP.NET Webforms 上.
I am new to ASP.NET MVC, most of my experience is on ASP.NET Webforms.
有没有办法根据域/主机名设置路由,即 www.domain.com 到一个区域,admin.domain.com 到另一个区域,www.differentdomain.com 到另一个区域,所有这些都在 Web 应用程序上.
Is there a way to setup routing based on domain/hostname, i.e. www.domain.com goes to one area, admin.domain.com to another and www.differentdomain.com to yet another area all on the web application.
另外,有没有办法做到包罗万象,即 *.domain.com 将被路由到另一个区域?
Also, is there a way to do a catch-all i.e. *.domain.com will be routed to another area?
推荐答案
可以使用域路由映射
routes.Add("DomainRoute", new DomainRoute(
"{customer}.example.com", // Domain with parameters
"{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
))
这篇关于基于域&的ASP.NET MVC路由主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文