Introduction
I have consulted many of the net books and found that most authors are standing on a higher level to explain the ASP. They are patient and meticulous in telling you how to drag and drop controls, set control properties, and write codebehind code to implement a specific function.
This practice, in effect, answers the question of " how to do " , but does not answer the question " Why do you do this "?
Although I highly appreciate Mr. Hua's book, "An explanation of the net development of the temple sacrifice," I decided to skip to the following chapters as I looked at the role and the user (Member). Because I found that he also followed the flow of this part of the explanation to stay on the "How to Do" level. I believe it is impossible for a bull like Mr. Siddhartha to understand the underlying workings simply because the book is already thick.
When you press "How to do" the content to develop the program, you are still a programmer for your users, but for Microsoft developers who implement the MembershipProvider and RoleProvider abstract classes, you have become one of their users.
NOTE : I have no objection to some authors explaining only "How to do it", nor are you only learning how to do it, and there is also the benefit of being able to develop it quickly. I'm just suggesting a little bit more knowledge of the bottom and a better understanding of some issues.
Hopefully, this series of articles will give you a better understanding of how ASP works and how to do it.
Http Request Processing Process Overview
Think "Why do I enter www.tracefact.net in the address bar to see Zhang Ziyang's personal space?" "It's like thinking," Why is the apple falling to the ground or not going up the sky? ”。 For ordinary visitors, it is just as natural that the sun rises to the west in the east of the day, and for many programmers, it is only the responsibility of the system administrator or network Manager to think that this has nothing to do with it. After all, IIS is a component of Windows and not a part of ASP. In fact, the IIS and. Net framework have done a lot of behind-the-scenes work from the moment you flick the carriage return to the page rendered within one-tenth seconds of your eyes.
You may find it irrelevant to understand how these behind-the-scenes work works, and as programmers you just have to ensure that the programs you develop can run efficiently. However, in the development process, you find that you often need to use classes such as HttpContext. At this time, have you ever thought about the composition of these classes and how the entities of the class were created? You may simply answer: HttpContext represents a context for the current request. But you know how IIS, the framework, and ASP. How do you work together to process each HTTP request, how to differentiate between different requests, IIS, the framework, and how does the data flow between ASP.
To answer these questions, you first need to understand how IIS handles page requests, which is the basis for understanding the form validation pattern and the Windows validation pattern.
Http when the request just arrived at the server
When the server receives an HTTP request, IIS first needs to decide how to handle the request (Note: the server handles an. htm page and an. aspx page must be different). What does IIS do with it? --According to the file's suffix name.
The server Gets the requested page (note: It can also be a file, such as Jimmy.jpg), the next step is to look for applications on the server that can handle such suffixes if IIS cannot find an application that can handle such files, and the file is not protected by the server side (note: A protected example is the file in App_Code, an unprotected example is your JS script, then IIS will return the file directly to the client.
Applications that can handle a variety of suffix names are commonly referred to as ISAPI applications (note:Internet Server application programe Interface, Internet Servers application interface). Although this ISAPI sounds very stylish, but also is an "application", but carefully look at its full name to understand: It is actually just an interface, acting as a proxy, its main work is to map the requested page ( file ) and the actual handler that corresponds to the prefix name.
Let's take a closer look at the ISAPI and see what it looks like, follow these steps:
- Open IIS.
- Select Random site, right mouse button, "Properties".
- Select the Home Directory tab.
- Select Configure.
You should see the following screen:
Figure 1. application Configuration
It is clear that all IIS can handle, or that the file type that the ISAPI provides the proxy service, and its corresponding actual spooler, are clearly listed here.
We find the application handler for the. aspx and then click "Edit" and the following screen appears:
Figure 2. editing handlers for . aspx files
As you can see here, all the. aspx files are actually handled by the Aspnet_isapi.dll program, and IIS submits a request for the. aspx page to aspnet_ After Isapi.dll, it was no longer concerned about how the request was subsequently handled. Now we should know thatASP . NET is just one component of the server (IIS) , which is an ISAPI extension.
Here are two points to note:
- When you modify limit to, you can restrict pages (files) to access only in a certain way
- "Confirming the existence of a file" is a key option for implementing URL mapping, which I'll talk about later.
understand the hosting environment ( Hosting )
In essence, ASP. NET is mainly composed of a series of classes, the main purpose of which is to translate the HTTP request to the client's response. The HttpRuntime class is a primary entry for ASP. It has a method called ProcessRequest, which takes a HttpWorkerRequest class as a parameter. The HttpRuntime class contains almost all the information about a single HTTP request: The requested file, server-side variables, QueryString, Http header information, and so on. ASP. NET uses this information to load, run the correct file, and convert the request to the output stream, in general, the HTML page.
NOTE : Two like, it can also be a picture.
When the content of the Web. config file changes or the. aspx file changes, in order to be able to unload applications running in the same process (note: Uninstallation is also for reloading), HTTP requests are placed in separate application domains.
NOTE : Maybe you've heard the application domain before, but you don't know what's going on, the application domain is the AppDomain.
For IIS, it relies on one called HTTP. SYS's built-in driver to listen for HTTP requests from outside. When the operating system starts, IIS first registers its own virtual path in HTTP. sys.
NOTE : This is actually the equivalent of telling HTTP. sys which URLs are accessible and inaccessible. A simple example: Why do you get 404 errors when you access files that don't exist? is determined in this step.
If the request is an accessible url,http. SYS will hand this request to the IIS worker process.
NOTE : IIS6.0 called w3wp.exe,iis5.0 in the name of aspnet_wp.exe.
Each worker process has an identity and a series of optional performance parameters.
NOTE : Optional Performance parameter refers to settings such as the recycle mechanism, timeout settings, and so on.
The next thing that's going on is the one in the previous chapter ISAPI up.
NOTE : This part of the content correlation is strong, in order to let everyone good understanding, I finally decided to put the ISAPI in front, maybe the full series will be adjusted again when finished.
In addition to mapping files and their corresponding handlers, the ISAPI needs to do some other work:
- Gets the current HTTQ request information from HTTP. SYS and saves the information to the HttpWorkerRequest class.
- Load httpruntime in a mutually isolated application domain appdomain.
- Call the ProcessRequest method of httpruntime.
Then the code that the programmer typically writes is done, and then IIS receives the returned data stream and returns it back to HTTP. SYS, and finally, HTTP. SYS then returns this data to the client browser.
OK, now you see Zhang Ziyang's Space homepage.
Figure 3.asp.net The hosting environment
Understanding Pipelines ( Pipeline )
In the previous two chapters, we discussed the things that IIS and the Framework did in the ephemeral one-tenth seconds of sending an HTTP request to seeing the browser output in a relatively low level. But we have overlooked one detail: How the code written by the programmer is cohesive in this process, and we'll look at this in this chapter.
When an HTTP request enters the ASP. NET runtime, its pipeline consists of a managed module (note:managed Modules) and a handler (Note:handlers), and the pipeline handles the HTTP request.
Figure 4. Understanding the Http Pipeline
Let's take a look at how the data in this picture is flowing.
1. httpruntime the HTTP request to Httpapplication,httpapplication, which represents the Web application created by the programmer. HttpApplication creates HttpContext objects for this HTTP request, which contain many other objects about the request, mainly HttpRequest, HttpResponse, HttpSessionState, and so on. These objects can be accessed through the page class or the context class in the program. 、
2. The next HTTP request passes through a series of module, which has full control over the HTTP request. these Module you can do something before you do some real work .
3. After the HTTP request passes through all the module, it is HttpHandler processed. In this step, you perform some actual operations, usually the business logic that is done by the. aspx page. You may feel that you have not experienced this process in creating an. aspx page, but you must know that the. aspx page inherits from the page class, and we look at the signature of the page class:
public class Page:templatecontrol, ihttphandler{
Code omitted
}
As you can see, the page class implements the IHttpHandler interface, and HttpHandler is the lowest level of HTTP request processing.
After the 4.HttpHandler is processed, the HTTP request returns to module once again, when module can do something that has already been completed.
NOTE : Notice the words I marked in red, and then recall: Is there a lot of Inserting, Inserted, and so on in ASP. In fact, here is why ASP. NET can divide an insert operation into two parts, and then separate the behind-the-scenes principle of event interception.
If we focus only on HTTP requests, HttpHandler and HttpModule, and do not consider HttpContext and HttpApplication, then Figure 4 can be simplified as follows:
Figure 5.Http Request in HttpHandler and the HttpModule flow direction in the
Summarize
In this article, I start by outlining the topics that this series of articles will cover for you. Then, I put forward a problem with some programmers: learning and using ASP at a relatively high level.
Then, I took a visit to my personal Space home page example, led to this article mainly about the three content:
- The work that IIS does when the HTTP request just arrives on IIS.
- The hosting environment for the HTTP request.
- HTTP pipeline.
I hope this article will bring you help.