Implementation Scheme of asp.net 2.0 for second-level website domain names

Source: Internet
Author: User
Tags website domain names

I understand two solutions. I hope you can discuss them more!
Basic Ideas:
1. Domain Name supports wildcard resolution, that is, resolve A record *. Domain Name. com to the server IP address, bind it to the server IIS, and the Host header is blank when binding;
2. to implement a complete second-level domain, create two sites, one for the master site, the other for the user, and both site directories refer to the same website directory.
3. host headers of second-level domain names in Web programs or URLs, such as abc in abc. Domain Name. com;
4. Use the obtained second-level domain name and store it in the Session for easy access
5. Use the obtained second-level domain name and URL to rewrite the address.
Implementation Method:
Domain name A record resolution Needless to say '', is to make A *. Domain Name. com A record resolved to your server IP

Method 1: second-level domain name URL redirection

A. Create a site and bind a domain name (win2003-IIS6) to IIS)
Open IIS, right-click the site, and click Properties. Click the Advanced button of the website item IP address, and click Edit or add to add a new binding. The host header value is blank.

The following code is used to obtain and determine the Host Header. The code is placed in Index. aspx. cs, the first file of the default document.

Code:

Reference content is as follows:
/// <Summary>
/// Obtain the second-level domain host header value and perform redirection
/// </Summary>
Public void CheckDomain ()
{
HostName = HttpContext. Current. Request. Url. Host. ToString (); // obtain the URL Host address
UserHost = HostName. Split (new Char [] {''.''}); // array, separated "."

// Determine whether the second-level domain name address complies with the abc. Domain Name. com format, and the length of the array UserHost is not greater than 3. Otherwise, the second-level domain name will jump to other pages.
If (UserHost. Length> 3)
{
HttpContext. Current. Response. Redirect ("http: // www. Domain Name. com/Error. aspx"); // jump to the Error page
Return;
}

UserDomainName = UserHost [0]. ToString (); // obtain the first group of values in the array and the Host header of the second-level domain name

// Make specific judgments and do not use the Host Header as the second-level domain name
If (UserDomainName. toLower () = "www" | UserDomainName. toLower () = "Domain Name" | UserDomainName = null | UserDomainName. toString () = "")
{
// Your actions
}
Else {
HttpContext. Current. Response. Redirect ("/User/"); // jump to the User directory, that is, the directory to which the second-level domain name is going. Of course, you can also jump to *. aspx? UserID = xxx
Return;
}

}


Now, abc. Domain Name. com can be redirected to a specified page or link, but it is not a real second-level domain name, but a URL redirection.
  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

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.