Asp.net| Virtual Host
Now asp.net virtual host can generally bind multiple domain names, but the pages opened through these domains are the same. 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.abc.com,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 is not "." Ah
int i = domain. IndexOf ('. ');
if (i > 0)
{
Take a domain name (for example, www.abc.com) the first "." The previous section (excluding the first ".") )
Sumdomain = domain. Substring (0, I);
If it is not "www", it automatically turns to Http://www.abc.com/xxx,
The URL of the address bar does not display http://www.abc.com/xxx, but displays the http://xxx.abc.com
if (Sumdomain.indexof ("www") = = 1)
{
Note that this sentence is the key
HttpContext.Current.RewritePath ("~/" + Sumdomain + Request.Url.PathAndQuery);
}
}
}
How, is not very simple! Haha, this is the URL rewrite (HttpContext.Current.RewritePath).