Let your asp.net virtual host also support subsites

Source: Internet
Author: User
Tags bind httpcontext domain domain name root directory
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).



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.