Implementation of ASP. NET multi-channel website architecture-. NET Programming Tutorial

Source: Internet
Author: User

Each channel is located in a different Web Project (with an independent second-level domain name), and all business logic and data access functions are encapsulated into a Class Library. All channels share this Class Library.

The implementation method is described in detail below.

Assume that the website has three channels: news, forums, and blogs. The corresponding second-level domain names are "news", "forum", and "blog ". In addition, two domain names need to be defined for the website homepage and user registration and login functions (based on the Passport mechanism, this article will be detailed later ), the corresponding domain names are "homepage" and "passport ".

1. Configure the URLs of each channel

A. Configure the hosts file

Open the hosts file (in c: \ windows or winnt \ system32 \ drivers \ etc \) in a text editor. The file contains the initial domain name resolution information. When we request a URL in a browser, the system first searches for the corresponding domain name in the hosts file. If yes, the system redirects to the specified IP address. If no domain name is found, the system submits DNS for domain name resolution.

The configuration is very simple. The format is like "[IP] [space] [domain name]". Each data entry corresponds to one row. The configuration content is as follows:

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 different channels correspond to different IP addresses, which is the development flexibility of the architecture. Different channels (Web projects) can be created on different developer computers. By synchronizing configuration content to various computers, you can easily browse pages between channels, just as these channels are on your own computer! This method can greatly reduce development coupling. Each channel is an independent module, and the Bug in one channel does not affect the other channel.

B. Configure Web. Config

Considering that the second-level domain names of each channel may be adjusted, it is a good way to store the corresponding configuration information in the Web. Config file. Similarly, the configuration information must be synchronized to various Web projects. The configuration content is as follows:

<Add key = "SiteDomainName" value = "mysite.com"/>
<Add key = "HomepageSiteURL" value = "http://www.mysite.com/homepage/"/>
<Add key = "PassportSiteURL" value = "http://passport.mysite.com/passport/"/>
<Add key = "NewsSiteURL" value = "http://news.mysite.com/news/"/>
<Add key = "ForumSiteURL" value = "http://forum.mysite.com/forum/"/>
<Add key = "BlogSiteURL" value = "http://blog.mysite.com/blog/"/>
<Add key = "LocalSiteURL" value = "/blog/"/>

The configuration items are described as follows:

SiteDomainName: the site domain name, such as "mysite.com", "mysite.com.cn", and "mysite.net. The usage of this configuration item is described later.

LocalSiteURL: the root path of the current channel, that is, the path of the website or virtual directory where the Web Project is located, starting. This configuration item is mainly used for reference within a channel, such as slice reference and Page Link.

Other configuration items: used for referencing between channels, such as channel navigation and function calling.

2. Create a Model component

In the composition of the MVC mode, the Model component includes all business logic operations, including data access operations.

This solution splits the Model component into three parts: Object entity, object operation, and data access, and encapsulates them into three Class libraries.

Because the design of the Class Library itself is a big topic, this article will not talk about it again. If you are interested, you can refer to some relevant materials.

Experience Sharing:

The preceding Model component splitting method is applicable to large-scale projects with complex business functions and requires a clear and refined division of labor within the team. But like ?????? ? O? If you are dealing with small and medium-sized projects, this method may become a bottleneck in development efficiency. This is mainly determined by the characteristics of the project. The business functions of small and medium-sized projects are less complex than those of large projects, and the number of developers is limited. A person is usually responsible for the development of the entire module. In this case, there are too many architecture layers. Each time you modify a layer, other related layers must also be modified synchronously, which affects the development efficiency.

3. Implement the Passport Mechanism

Many websites use Session to store personal information, such as logon information, and use the Session as the basis for determining whether a user logs on. However, a Session has a defect, that is, it cannot be shared among multiple Web applications. A Session generated by a Web application can only be used by itself. Which method can achieve data sharing among multiple Web applications? The answer is Cookie. The Cookie stores the information on the client and sends it back to the server as needed.

Passport, that is, a pass, is a user identity authentication mechanism widely used at present. In simple words, it is a single login and full-site access. This is our requirement.

The pass mechanism discussed here is based on cookies, which makes it easier to implement. The key point is the setting of the Cookie's Domain attribute. The Domain attribute indicates the target Domain for sending the Cookie information back, that is, the Domain for receiving the Cookie. The Domain for receiving the Cookie must be consistent with the Domain for sending the Cookie, otherwise, it is invalid. For example, if 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 receiving domains. To enable all channels to receive cookies, you must set the Domain attribute to a form without a second-level Domain name prefix, such as "mysite.com", "mysite.com.cn", and "mysite.net.

After successful logon, the system sends the corresponding Cookie to the client, which may include some global information, such as the user ID and user name. When you exit, delete the corresponding Cookie. Note that you must set the correct Domain attribute When deleting the Cookie.

There are two other questions about the Passport mechanism:

A. Cookie expiration time

There are two solutions available. One is the default method, that is, the Expires attribute of the Cookie is not set. In this solution, the Cookie is stored in the memory, the Cookie will remain in the logon status until the browser is closed. This method is mainly used for websites that do not have high requirements on information security, such as entertainment and leisure websites. The other is to specify a specific expiration time, generally, the last time the user accesses the website plus a timeout period is used as the expiration time, which is similar to the session Timeout mechanism in asp. This method is mainly used for websites with high security requirements, such as online banking and email.

B. Cookie Information Security

Because cookies transmit data in plaintext mode, security risks are inevitable. Therefore, it is necessary to encrypt important data. Reversible algorithms can be used for encryption, such as DES.

4. Create a Web Project

As mentioned above, Web Project creation is flexible. It can be created on different developer computers or on the same computer. This depends on the size of the development team.

5. Deployment

Deploy channels, set second-level domain names, and change the configuration in Web. Config to the actual data in the production environment.

Among them, the complex work is the deployment of the same part in various channels, such as the website header (Logo, navigation bar, etc.), the bottom of the website (copyright statement, contact information, etc.), pictures, CSS, javaScript. Of course, you can also deploy these public resources in a single channel for other channels to call. However, doing so undermines the loose coupling of various channels, if the channels used to store public resources are faulty, the other channels will not work properly.

End

This article discusses an implementation method of Asp.net multi-channel website architecture. Due to the large amount of content involved, it cannot be expanded one by one. However, it adds a bit of ink to the key part, 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.