Alternative second-level domain name Implementation Method

Source: Internet
Author: User

I stated before: Mr. Smith is not very clear about the concepts of "second-level domain names" and "sub-stations". If this article is a little useful to you, he will keep a smiling face; if not, if you think it is completely time-consuming, please make a brick. If you have a better and simpler method, you can also propose it for everyone (especially me) to learn ......

In the past few days, the takeout Internet site has begun to implement expansion in other cities (currently available on the Hangzhou site and is preparing to activate the Shanghai site), but it has encountered a problem (not to mention that everyone knows ), that is, how to direct a second-level domain name to sites in different cities. Currently, the domain name of the takeout is waimaihui.com. This can be implemented simply by configuring DNS. However, considering the expansion of other cities in the future, if DNS is configured, the scalability is too bad. Therefore, we should consider implementing it through a program.

Considering that data between cities is basically not interactive, every city uses an independent database (of course, this is not a good solution ), this makes different cities only have different databases, and the others are the same. Apart from the page content such as the webpage title, this is just a new city name.

Therefore, I came up with an alternative method: To determine which city the user accesses by determining the hostname requested by the user, different cities use different database connection strings, these database connection strings are kept as web. the key value in config.

H ostname = httpcontext. current. request. URL. host. tostring (); // obtain the URL host address

Userhost = hostname. Split ( New Char [] { '.' }); // Array, separated "."


Determine the city site accessed by the user by judging the value of Userhost [0. For example, the user requests a page at http://hz.waimaihui.com/then userhost=0133 = "HZ"

Another problem is also encountered: when to set this string, you cannot determine the user's access, maybe the user's access time in the previous second?

I chose to introduce Global. asax, whichApplication_beginrequestDetermine the page of the user request in the event, and set the connection string to different key values. This event will be triggered each time the user requests the page, in this way, you can always keep the correct connection string.

 

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.