How to make the binding of these several domain names open the page (that is, the function of the subsite)? In fact, it's simple, just 4 steps:
1 bind several domain names to the virtual host; for example: www.bianceng.cn,services.abc.com,support.abc.com.
2 Create several folders under the root directory of the virtual host site; For example: Services,support;www folder is not built.
3 under vs. a Web project, create the same folders, add a Default.aspx file under each folder; for example: Services,support.
4 Add Application_BeginRequest event in Global.asax:
protected void Application_BeginRequest(object sender, EventArgs e)
{
string sumDomain;
string domain = Request.Url.Host;
// http://localhost 可没有“.”啊
int i = domain.IndexOf('.');
if (i > 0)
{
// 取域名(例如,www.abc.com)第一个“.”之前的部分(不包括第一个“.”)
sumDomain = domain.Substring(0, i);
// 如果不是“www”,则自动转向到 http://www.abc.com/xxx,
// 地址栏的URL,不会显示http://www.abc.com/xxx,而是显示http://xxx.abc.com
if (sumDomain.IndexOf("www") == -1)
{
// 注意,这一句是关键
HttpContext.Current.RewritePath("~/" + sumDomain + Request.Url.PathAndQuery);
}
}
}
How, is not very simple! Haha, this is the URL rewrite (HttpContext.Current.RewritePath).