Reprinted -- dotnetnuke 5 C # version 2--http modules

Source: Internet
Author: User
Tags dnn dotnetnuke

In frontArticleThe dnn architecture is described in. The figure below shows a more comprehensive understanding of its structure:

If you are a beginner in Asp.net, we suggest you look at the previous section because it will introduce you to what is the HTTP module and some other concepts. I want to read this article to understand the mechanism of Asp.net and some in-depth things. I tried to let everyone know what I wrote, not just to follow me to do something, but to understand it. I even want to know why I want to do this. Too much nonsense...

Before entering the topic HTTP module, you need to understand several concepts. The explanation of HTTP pipeline. Wikipedia is as follows:

HTTP pipelining is a technique in which multiple HTTP requests are written out to a single socket without waiting for the corresponding responses. pipelining is only supported in HTTP/1.1, not in 1.0.

The pipelining of requests results in a dramatic improvement [citation needed] in page loading times, especially over high latency connections such as satellite Internet connections.

Since it is usually possible to fit several HTTP requests in the same TCP packet, HTTP pipelining allows fewer TCP packets to be sent over the network, loading network load.

Non-idempotent methods like post shoshould not be pipelined. sequences of get and head requests can be always pipelined. A sequence of other idempotent requests like get, head, put and delete can be Pipelined or not depending on whether requests in the sequence depend on the effect of others. [1]

HTTP pipelining requires both the client and the server to support it. HTTP/1.1 conforming servers are required to support pipelining. this does not mean that servers are required to pipeline responses, but that they are required not to fail if a client chooses to pipeline requests.

Http://en.wikipedia.org/wiki/HTTP_pipelining

To put it bluntly, you do not need to wait for the server's response to send multiple HTTP requests to the server, which greatly reduces the page loading time.

Asp.net provides several methods to implement HTTP pipeline. HTTP module, which is widely used, is a user-defined component method.

If you are better at English, we suggest you read the following link to learn about HTTP pipeline and HTTP module,

Http://msdn.microsoft.com/en-us/magazine/cc301362.aspx

Http://msdn.microsoft.com/en-us/library/ms178473 (V = vs.80). aspx

If you want to look at the comfortable Chinese, we suggest you read the following article about the HTTP request processing process written by the eldest brother:

Http://en.wikipedia.org/wiki/HTTP_pipelining

HTTP handler introduction:

Http://www.tracefact.net/Asp-Net-Architecture/Introduction-to-Http-Handler.aspx

And HTTP module introduction:

Http://www.tracefact.net/Asp-Net/Introduction-to-Http-Module.aspx

It contains many examples. You can learn while watching. And he spoke very well.

If you have carefully read the above content, I believe you have understood the role of the HTTP module. You will also understand what global. asax is doing in the. NET project. The general request process is as follows:

 

 

Evolution of HTTP modules and HTTP module events in dnn

Now let's look at dnn'sSource codeSome are called HTTP modules.

 

In fact, the earlier versions of dnn also put all HTTP modules in global. asax. VB (because the previous versions are VB versions ). Later, we put these modules into the HTTP module. The reason is as follows:

    1. The administrator can add or remove these modules in the system because they are modules.
    2. Developers canProgramThat is, when dnn. liabrary is used, you can modify or replace these HTTP modules.
    3. We provide a template for extending HTTP pipeline. Because you can add your own HTTP Module

Some HTTP modules that come with. NET Framework are stored in a config file under. Net framewrok. The expanded HTTP module also needs to be stored in

Configure dnn in Web. config:

 

We know that the HTTP module inherits the ihttpmodule interface.

 

In the init method, we delegate a certain event of context.

HTTP module events are divided into three types:

    1. Occurs before the application is executed.

Mainly include:

Beginrequest: It is triggered every time a program sends a request to the server.

Authenticaterequest: indicates that the server authentication is prepared for the request. It is used in Authentication mode.

Authorizerequest: indicates that the server is ready for authorization.

Resolverequestcache: Use the cache in the output cache module to shorten the request.

Acquirereuqeststate: indicates that the status before the request can be obtained.

Prerequesthandlerexecute: the last event that you can trigger before the HTTP request of the program occurs.

After the application is executed:

Postrequesthandlerexecute: This event occurs after the HTTP processing program is executed. Releaserequeststate: stores the session state in the state storage again. If you want to build a custom

Session Status Module, you must store your status in the status store again.

Updaterequestcache: This event re-writes the output to the output cache. If you want to build a custom cache module, you can write the output to the cache again.

Endrequest: the request has been completed. You may want to build a debugging module to collect the entire request information and then write the information to the page.

 

URL writer HTTP module in dnn

URL rewriting is required by a good system. Dnn URL rewriting also provides many URL rewriting formats. In the final analysis, it is also for URL-friendly and Seo-friendly. Below is a friendly URL of dnn:

Http://www.dotnetnuke.com/RoadMap/FriendlyURLs/tabid/622/default.aspx

If you are not familiar with URL-friendly, please Google or ask for leave.

URL rewriting occurs in the HTTP pipeline request, so it can be used as an event of the entire application. The HTTP module event used here is beginrequest. That is to say, each page

Before sending an HTTP handler request to the server, use the beginrequest event to convince the server that your url is the page of the next request.

This conversion process is completed by using the regular expression in the siteurls. config file.

 
  <? XML version = "1.0" encoding = "UTF-8"?>

<Rewriterconfig>

<Rules>

<Rewriterrule>

<Lookfor>. */Tabid/(\ D +) (. *)/logoff. aspx </lookfor>

<Sendto> logs/admin/security/logoff. aspx? Tabid = $1 </sendto>

</Rewriterrule>

<Rewriterrule>

<Lookfor>. */Tabid/(\ D +) (. *)/RSS. aspx </lookfor>

<Sendto> logs/RSS. aspx? Tabid = $1 </sendto>

</Rewriterrule>

<Rewriterrule>

<Lookfor> [databases?] */Tabid/(\ D +) (. *) </lookfor>

<Sendto> logs/default. aspx? Tabid = $1 </sendto>

</Rewriterrule>

</Rules>

</Rewriterconfig>

 

The nodes are lookfor and sendto. Yes. That is to say, when the program finds that the URL is... When Tabid/622/RSS. aspx is used, it will find RRS. aspx? Tabid = 622.

The following url isCodeIt can be another URL.

If the URL is

Http: // localhost/dotnetnuke_community_cs/Tabid/21/portalid/0/default. aspx then the actual URL is default. aspx? Tabid = 21.

Of course, if you like it, you can forcibly compare a specific URL without using a regular expression.

 

 
  <Rewriterrule>

<Lookfor>. */xxoo/url. aspx </lookfor>

<Sendto> logs/default. aspx? Tabid = 622 </sendto>

</Rewriterrule>

 

 

 

Next we will analyze the basic dnn URL given above:

Http://www.dotnetnuke.com/RoadMap/FriendlyURLs/tabid/622/default.aspx

Http://www.dotnetnuke.com --- is the URL of the entire website

Roadmap/friendlyurls --- is the name of the navigation menu. That is, the name of the level 1 menu. You can try it on the dnn official website.

Tabid/622/--- is the parameter (? Tabid = 622)

Default. aspx --- the most important page in dnn...

 

Of course, whether the navigation menu needs to be displayed in the URL can be set through the friendlyurl section in the web. config file. For a small website, you do not need to classify it on the main website,

For example, product and community are not required.

 

The biggest advantage of dnn URL rewriting is that you do not need to search for data from the server to prepare for URL rewriting, but use a regular expression. I have seen many websites rewrite URLs without stopping

Interacting with databases can affect the performance of large websites.

The above URL format is good for Seo, but most people want a URL that is easy to remember, that is, the legendary humanization. But this is only suitable for small websites, and you can write

In the configuration file above. Dnn5 also has a configuration that makes the URL human friendly. I will not talk about it here.

Dnn URL rewriting also uses the provider module mode. do not extend its URL rewriting. I have to admire its scalability. It is everywhere...

 

Since it is highly scalable, how can I rewrite the provider by writing a URL?

First, you need to create a provider class that inherits the following class:

 

Then you write your company's URL from the write rules in these methods. I will give an example in the following article. After writing this compilation, you only need

Add the provider.

 

Code

 
  <Friendlyurl defaultprovider = "customfriendlyurl">

<Providers>

<Clear/>

<Add name = "dnnfriendlyurl"

Type = "dotnetnuke. Services. url. friendlyurl. dnnfriendlyurlprovider,

Dotnetnuke. httpmodules. urlrewrite "includepagename =" true"

Regexmatch = "[Your a-zA-Z0-9 _-]"/>

<Add name = "customfriendlyurl"

Type = "companyName. friendlyurlprovider, companyName. friendlyurlprovider"/>

</Providers>

</Friendlyurl>

 

 

 

The above is a rough description of how dnn URL rewriting is performed. Code-level research and custom URL rules will be introduced in a separate article.

PS: If you have mastered dnn URL rewriting, You can port it to your project.

 

Dnn exception HTTP Module

 
The above URL rewriting part uses the beginrequest event, and the exception module needs to execute a method when an error occurs in the entire application. The Code is as follows:
 
 
 
The exception information is also stored in the database for analysis by developers.
 
 
 
Dnn's useronline HTTP Module
 
This module listens to the authorizerequest event. Each time a user sends an identity authentication to the server, the HTTP module sends a request to the server, and the useronlineprovider executes the request.
 
 
 
Dnn's usernolineprovider uses cookies to store unique identifiers. This prevents online visitors from being recorded repeatedly. Of course, this function mainly relies on the scheduler module of dnn.
 
There is a thread in the background to execute in a few minutes.
 
The Code-level research of the dnn useronline module will also be introduced in a later article. You can understand the principle here.
Other modules include membership, compression, requestfilter, analytics, and compression. The analytics function is a good reference for many people who monitor website data traffic.
 
I will describe the description and requestfilter. It is estimated that the next part of the HTTP module will have to write 7-8 articles.
 
Cheers
 
Nic
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.