1. httpcontext indicates a context of the current request.
1. When an HTTP request arrives at the server (In a word, when the server receives an HTTP request, it will use the ISAPI in IIS to find the corresponding suffix file processing.ProgramFor example, when the suffix of the request file is aspx, ISAPI maps the fileAspnet_isapi.dll)ASP. NET is only an integral part of Server (IIS). It is an ISAPI extension.
When the server receives an HTTP request, IIS searches for applications that can handle such extensions Based on the file suffix, that is, ISAPI applications (Note: Internet server application programe interface, internet server application interface ). Although this ISAPI sounds very elegant, it is also an "application", but you can take a closer look at its full name to understand that it is actually only an interface and acts as a proxy, the main task is to map the requested page (File) and the actual processing program corresponding to the extension. If IIS cannot find an application that can process such files, this file is not protected by the server (Note: A protected example is the file in app_code, and an unprotected example is your JS script ), then IIS will directly return this file to the client.
Let's take a closer look at the ISAPI and see what it looks like,
Follow these steps:
1. Open IIS.
2. Select a random site, right-click the site, and select "properties ".
3. Select the "home directory" tab.
4. Select "configuration ".
Figure 1. Application configuration
Clearly, we can see that all the file types that can be processed by IIS or that is called the proxy service provided by ISAPI and their corresponding actual background processing programs are clearly listed here. Find the. aspx application handler and click "edit". The following figure is displayed:
Figure 2. Edit the. aspx file Handler
All the way here, we can see that,All. aspx files are actually processed by the aspnet_isapi.dll program. When IIS submits a request for the. ASPX pageAfter aspnet_isapi.dll, it no longer cares about how the request is processed.
Now we should know:ASP. NET is only an integral part of Server (IIS). It is an ISAPI extension.
Note the following two points:
· After you change "limit to", you can restrict access to pages (Files) in a specific way.
· "Check whether a file exists" is a key option for URL address ing. I will detail it later.
Understanding the host environment (hosting)
In essence, ASP. NET is mainly composed of a series of classes whose main purpose is to convert HTTP requests into responses to clients. The httpruntime class is a main entry of ASP. NET. It has a method called processrequest. This method uses an httpworkerrequest class as a parameter. The httpruntime class contains almost all information about a single HTTP request: the requested file, server variables, querystring, and HTTP header information. ASP. NET uses this information to load and run the correct file and convert the request to the output stream. Generally, it is an HTML page.
Note:In other words, it can also be an image.
When the content of the Web. config file changes or the. aspx file changes, in order to uninstall the application running in the same process (Note:To reload), HTTP requests are divided into isolated application domains.
Note:You may have heard of the application domain before, but you don't know what's going on. The application domain is appdomain.
For IIS, it depends on a built-in driver called HTTP. sys to listen to HTTP requests from outside. When the operating system is started, IIS first registers its own virtual path in HTTP. sys.
Note:Actually, it is equivalent to telling HTTP. sys which URLs are accessible and which are inaccessible. For example, why do you encounter a 404 error when accessing a non-existent file? It is determined in this step.
If the request is an accessible URL, HTTP. sys will send the request to the IIS worker process.
Note:Iis6.0 is called w3wp.exe, and iis5.0 is called aspnet_wp.exe.
Each worker process has an identity and a series of optional performance parameters.
Note:Optional performance parameters, such as the recycle mechanism settings and timeout settings.
The next step is the ISAPI described in the previous chapter.
Note:This part of the content is highly correlated. In order to make everyone better understand it, I decided to put the ISAPI in front of it. It may be adjusted when the full series is completed.
In addition to the corresponding handler of the ing file, ISAPI also needs to do some other work:
- Obtain the current httq request information from HTTP. sys and save the information to the httpworkerrequest class.
- Load httpruntime in the appdomain of the mutually isolated application domain.
- Call the processrequest method of httpruntime.
The next step is what programmers usually writeCodeAfter the work is completed, IIS receives the returned data stream and returns it to HTTP. sys again. Finally, HTTP. sys returns the data to the client browser.
OK. Now you can see Zhang Ziyang's space homepage.
Figure 3. ASP. NET host environment
Understanding Pipelines)
In the previous two chapters, we discussed at a relatively low level what IIS and framework did in a second from sending an HTTP request to seeing the browser output. However, we ignore the details of how the Code Compiled by the programmer is connected in this process. Let's take a look at this issue in this chapter.
When an HTTP request enters ASP. net runtime, its pipeline consists of a hosting module (Note: managed modules) and a processing program (Note: handlers), and the pipeline is used to process this HTTP request.
Figure 4. Understand the HTTP Pipeline
Let's take a look at how the data in this figure flows by number.
1. httpruntime transfers an HTTP request to httpapplication. httpapplication represents a web application created by a programmer. Httpapplication creates an httpcontext object for this HTTP request. These objects contain many other objects related to this request, including httprequest, httpresponse, and httpsessionstate. These objects can be accessed through the page class or context class in the program. ,
2. Next, the HTTP request uses a series of modules that have full control over the HTTP request.These modules can do things before performing a specific task..
3. After the HTTP request passes through all modules, it will be processed by httphandler. In this step, perform some actual operations, usually the business logic completed on the. ASPX page. You may not understand this process when creating the. ASPX page. However, you must know that the. ASPX page inherits from the page class. Let's take a look at the page class signature:
Public class page: templatecontrol, ihttphandler {
// Code omitted
}
As you can see, the page class implements the ihttphandler interface, and httphandler is also the lowest layer for HTTP request processing.
4. After httphandler completes processing, the HTTP request returns to the module again,At this time, the module can do some things after some work has been completed.
Note:Pay attention to the words marked in red, and think back: Is there many paired events such as inserting and inserted in ASP. NET? In fact, ASP. NET can divide an insert operation into two parts, and then intercept the background principles of the event separately.
If we focus only on HTTP requests, httphandler, and httpmodule without considering httpcontext and httpapplication, figure 4 can be simplified as follows:
Figure 5. http request flow direction in httphandler and httpmodule
Summary
In this article, I will first outline the seriesArticleThe theme to be discussed. Then, I raised a question for some programmers: learning and using ASP. NET at a relatively high level.
Later, I took an example to access my personal space home page and introduced three things described in this article:
- What does IIS do when an HTTP request arrives at iis.
- The host environment of the HTTP request.
- HTTP pipeline.
I hope this article will help you.
Httpruntime is used to configure the Asp.net HTTP runtime settings to determine how to process requests to the Asp.net application.
Executiontimeout: maximum time limit allowed for request execution, in seconds
Maxrequestlength: indicates the maximum file upload size supported by ASP. NET. This restriction can be used to prevent DoS attacks caused by a large number of files being transferred to the server. The specified size is in KB. The default value is 4096 KB (4 MB ).
Usefullyqualifiedredirecturl: indicates whether the client redirection is fully qualified (in the "http: // server/path" format, which is required by some mobile controls ), or indicates whether to send relative redirection to the client. If it is true, all non-fully-qualified redirects are automatically converted to a fully-qualified format. False is the default option.
Minfreethreads: specifies the minimum number of free threads allowed to execute new requests. ASP. NET allows a specified number of threads to remain free by appending threads to complete the requests it processes. The default value is 8.
Minlocalrequestfreethreads: the minimum number of free threads allowed to execute new local requests maintained by ASP. NET. The number of threads is reserved for requests passed in from the local host to prevent some requests from sending subrequests to the local host during processing. This avoids possible deadlocks caused by recursive re-entering the web server.
Apprequestqueuelimit: indicates the maximum number of requests that ASP. NET will queue for the application. Requests are queued when there are not enough free threads to process requests. When the queue exceeds the limit specified in this setting, the incoming request is rejected through the "503-the server is too busy" error message.
Enableversionheader: Specifies whether ASP. NET should output the version header. Microsoft Visual Studio 2005 uses this attribute to determine the current ASP. NET version. This attribute is not required for the production environment and can be disabled.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zhanglei5415/archive/2008/03/11/2168732.aspx