ASP. NET multi-channel website architecture Implementation Method

Source: Internet
Author: User
Main Architecture

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 must be defined,
The domain names are "Homepage" and "Passport ".

1. Configure URLs for each channel

A. Configure the hosts file

Open the hosts file (in c: \ windows or WINNT \ system32 \ drivers \ etc \) in a text editor.
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 the 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. Channels (Web
Project) 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! Collection
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 part

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 branch? 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 developers
The number is also relatively limited, and often one person is 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 be modified synchronously, which affects 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, the session has one defect, that is, it cannot
For sharing in 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 cookie domain attribute setting, which 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 the same as the domain for sending the cookie. Otherwise, the domain 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 make all channels receive cookies, you must set domain
Set the 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, before the browser is closed
The cookie will remain in the logon status. 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.
In general, the last time the user accesses the website plus a timeout period as the expiration time is a bit similar to the Session Timeout mechanism in ASP. This method is mainly used for security requirements
High websites, 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 EncryptionAlgorithmSuch 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, this will destroy the loose coupling feature of each channel. If it is used to store public resources
If there is a problem with the Channel, 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 :-)
Transferred from: Tianji

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.