Asp. NET multi-channel Web site architecture Implementation method

Source: Internet
Author: User
Tags config functions key net domain domain name client

Each channel is located in different Web Project (with a separate level two domain name) and encapsulates all business logic and data access functionality into the class library, which is shared by all channels.

The implementation method is described in detail below.

If the site has three channels, news, forums and blogs, the corresponding level two domain name for "news", "Forum", "blog." In addition, also need to define another two domain names, respectively for the home page and user registration, login function (based on the passport mechanism, this article will be described in detail later), corresponding to the domain name "homepage", "Passport."

1. Configure each channel URL

A, configure the Hosts file

Open the Hosts file (located in C:\Windows or winnt\system32\drivers\etc\) with a text editor that holds the initial domain name resolution information. When we request a URL in the browser, the system first in the hosts file to find the appropriate domain name, if found to jump to the designated IP, if not found, then further submit DNS for domain resolution.

Configuration is simple, format such as "[ip][space] [domain name]", each data corresponds to one row. The following are the configuration contents:

192.168.1.2 www.mysite.com

192.168.1.2 passport.mysite.com

192.168.1.3 news.mysite.com

192.168.1.5 forum.mysite.com

192.168.1.9 blog.mysite.com

You may have noticed that each channel corresponds to a different IP, which is where the architecture's development flexibility lies. Each channel (Web Project) can be created on a different developer computer. By synchronizing the configuration content to each computer, you can easily navigate between channels, just like these channels are located on your own computer! This approach can greatly reduce the development of coupling, each channel is a stand-alone module, a channel of bugs will not affect the other channel.

B, configure Web.config

It is a good idea to store the corresponding configuration information in the Web.config file, considering the possible adjustment of the level two domain name of each channel. Similarly, the configuration information must be synchronized to each of the Web Project. The following are the configuration contents:

The configuration items are described below

Sitedomainname: Site domain name, form such as "mysite.com", "mysite.com.cn", "mysite.net" and so on. The usage of this configuration item will be described later in this article.

Localsiteurl: The current channel root path, which is the path to Web project's Web site or virtual directory, starts with "/". This configuration item is used primarily for references within channels, such as picture references, page links, and so on.

Remaining configuration items: used for reference between channels, such as channel navigation, function calls, and so on.

2. Create Model Parts

In the MVC pattern composition, the model part includes all the business logic operations, which also contain data access operations.

This scenario splits the model part into object entities, object operations, and data access three parts, encapsulated into three class Library.

Because the class library design itself is a very big topic, this article is no longer described, interested in the words can refer to some relevant information.

Experience Sharing:

The above model part splitting method is suitable for large projects with complex business functions, requiring a clear and detailed division of work within the team. But as?????? O is faced with small and medium projects that are likely to be a bottleneck in development efficiency. This is mainly determined by the characteristics of the project, small and medium-sized project business functions compared to large projects are not so complex, the number of developers is also relatively limited, often a person to be responsible for the development of the entire module. In this case, the architecture level is too numerous, each time modifying a layer, the other related layer also must follow the synchronized modification, thus affecting the development efficiency.

3. Implementation of the passport mechanism

Many sites use session to store personal information, such as login information, and as a user login or not to judge the basis. But the session has a flaw in that it cannot be shared across multiple Web applications, and a Web application-generated session can only be used by himself. Which method can realize data sharing in multiple Web applications? The answer is cookies. Cookies store information on the client and send it back to the server side when needed.

Passport, that is, the pass, is currently widely used as a user identity authentication mechanism, in simple terms is a login, the whole station pass. That is exactly what we are asking for.

The pass mechanism discussed here is based on cookies and is more convenient to implement. The key point is the cookie's Domain property setting, which represents the target domain of the cookie information postback, which is the domain that receives the cookie, and the domain that receives the cookie must be the same as the domain that sent the cookie, otherwise it is not valid. For example, the sending domain is "blog.mysite.com", the receiving domain can be set to "blog.mysite.com" or "mysite.com", and "news.mysite.com" and "blog.yoursite.com" are invalid receive domains. For all channels to receive cookies, the domain attribute must be set to a form without a level two domain prefix, such as "mysite.com", "mysite.com.cn", "mysite.net", and so on.

After successful login, send the appropriate cookie to the client, which can include some global information, such as user ID, user name, etc. Delete the appropriate cookie when the user exits, especially if you want to set the correct domain attribute when you delete the cookie.

With regard to the passport mechanism, two other issues are worth discussing:

A, the expiration time of the cookie

There are two options, one is the default, the cookie is not set the Expires property, in this scenario, the cookie is stored in memory, before the browser shutdown, the cookie will always exist, that is, has been logged on. This approach is mainly used for information security requirements are not very high web sites, such as entertainment and leisure sites; the other is to specify a clear expiration time, typically the user's last visit to the site plus a timeout period as an expiration time, somewhat similar to the ASP in the session timeout mechanism, This approach is mainly used for high security requirements of the site, such as online banking, e-mail and so on.

b, the information security of cookies

Because the cookie is in the clear text transmission data, unavoidable exists the security hidden danger, therefore to the important data encryption is very necessary. Encryption can take a reversible algorithm, such as DES.

4. Create Web Project

As mentioned earlier, WEB project creation is more flexible and can be created either on a different developer computer or on a single computer. This depends largely on the size of the development team.

5, deployment

Deploy each channel separately, set level two domain name, change the related configuration in Web.config to the actual data of production environment.

The more complicated work is the same part of each channel deployment, such as the head of the site (Logo, navigation bar, etc.), the site at the bottom (copyright notices, contact methods, etc.), pictures, Css,javascript and so on. Of course, these public resources can be deployed on a separate channel for other channels to invoke, but this will undermine the loose coupling of the characteristics of each channel, if the channel used to store public resources problems, the remaining channels will not be normal use.

End

This paper discusses the asp.net of multi-channel Web site architecture in a way, due to the content of more, can not be launched, but the focus of the part or add more ink, hope to be useful to you.



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.