基于域和放大器ASP.NET MVC路由;主机名 [英] ASP.NET MVC Routing based on domain & hostname

查看:84
本文介绍了基于域和放大器ASP.NET MVC路由;主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的ASP.NET MVC,我的大部分经验是ASP.NET Web表单。

有基于域/主机名的方式来设置路由,即www.domain.com进入一个领域,admin.domain.com到另一个www.differentdomain.com到另一个领域的Web应用程序的所有。

此外,有没有办法做一个包罗万象的,即* .domain.com将被路由到另一个领域?


解决方案

您可以使用域路由映射

\r
\r

routes.Add(DomainRoute,新DomainRoute(\r
    {}客户.example.com的,//域名与参数\r
    {}动作/(编号),// URL带参数\r
    新{控制器=家,行动=索引,ID =} //参数默认\r
))

\r

\r
\r

域与ASP路由。净MVC

I am new to ASP.NET MVC, most of my experience is on ASP.NET Webforms.

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.

Also, is there a way to do a catch-all i.e. *.domain.com will be routed to another area?

解决方案

you can use Domain Routing mapping

routes.Add("DomainRoute", new DomainRoute( 
    "{customer}.example.com", // Domain with parameters 
    "{action}/{id}",    // URL with parameters 
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults 
))

domain routing with asp.net mvc

这篇关于基于域和放大器ASP.NET MVC路由;主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆