The essence of ASP. NET [What is ASP. NET ?]

Source: Internet
Author: User
Tags website server what is asp
Document directory
  • 1. Net host
  • 2. ISAPI filter
  • 3. What is ASP. NET in essence? [ASP. NET operating mechanism]
  • 4. Conclusion

ASP. NET is a technical framework provided by Microsoft to compile dynamic websites. It features a. Net-based framework. All ASP. NET programs can be written in. Net-based languages. In Microsoft's vs development platform, convenient functions such as drag-and-drop controls are implemented, enabling ASP. NET application development efficiency has been greatly improved, this year ASP. net has gradually become one of the mainstream technologies for website development.

But what is the essence of ASP. NET? To answer this question, we will first introduce two concepts.

1. Net host

As a technical framework dedicated to running on a Windows operating system, the implementation of. Net fully reflects this point .. Net team essentially implements CLR as a standard COM server component. CLR has a standard COM interface and interface guid, which is installed in.. net, CLR will be registered in the operating system as a COM server. You can use the oleview tool provided by Vs to view the registered COM components on the operating system and display the CLR registered on the debuglzq notebook.

Register as the CLR of the COM Server

You can find this tool from the path.

As a standard COM server, CLR can be loaded and used by clients. That is to say, in unmanaged code, a CLR can be loaded by loading a COM server, in this way, the CLR loads the Assembly and module, and then runs the managed code.

The following is a simple example of CLR loading.

The simple managed assembly code is as follows:

Using system; namespace net. MST. eighth. simpleassembly {/// <summary> /// a simple assembly that outputs the input string /// </Summary> public class simpleassembly {static int writestring (string S) {console. writeline ("CLR host output:" + S); return 1 ;}}}

Load the CLR running managed code in the unmanaged code. The Code is as follows:

// Loadclr. CPP: defines the entry point for the console application. // # include "stdafx. H "# include <windows. h> // define the version of CLR # include <mscoree. h> # pragma comment (Lib, "mscoree. lib ") // load CLR to run the managed code void main (INT argc, _ tchar * argv []) {iclrruntimehost * phost; hresult hR = corbindtoruntimeex (null, null, 0, clsid_clrruntimehost, iid_iclrruntimehost, (pvoid *) & phost); phost-> Start (); iclrcontrol * clrcontrol = NULL; HR = phost-> getclrcontrol (& clrcontrol ); DWORD * returnvalue = NULL; // start running the managed code phost-> executeindefaappappdomain (L ".. \\.. \\.. \ simpleassembly \ bin \ debug \ simpleassembly. DLL ", l" net. MST. eighth. simpleassembly. simpleassembly ", l" writestring ", l" http://www.cnblogs.com/DebugLZQ ", returnvalue); System (" pause "); // uninstall CLR at end}

The program running result is as follows:

As shown in the code above, using the clr com Service in unmanaged code is very easy to comment on. com will be uninstalled at the end of the Code. Of course, more code may be required in the system to ensure the loading and uninstallation are completed effectively.

At this point, I may be confused about the relationship between the. NET host concept and ASP. NET? In fact, Asp. net is a CLR host, that is, Asp. net work code is similar to the above Code: Load Clr and run the hosted website server code, that is why ASP. net is based on.. NET Framework.

2. ISAPI filter

Before describing the detailed behavior of ASP. NET as the CLR host, you must first explain the concept of ISAPI. The full name of ISAPI is Internet Server Extension application, while ISAPI filter is a DLL running on the HTTP server that starts ISAPI, which can be used to process specific HTTP requests, for example, binding all HTM files to an ISAPI filter causes all requests to the HTM files to be processed through this ISAPI filter.

ASP. net is an ISAPI filter, all ASP, such as aspx, ascx, asmx, and ASP under smooth conditions.. NET Server Web page files are bound to ASP.. Net to load the CLR and run the managed code for processing.

Let's explain it in the previous figure. the figure obtained from Baidu shows the problem, and the figure shows the truth.

The list of isapis in IIS after ASP. NET is installed is displayed. It is clear that ASP. NET runs as an ISAPI filter.

3. What is ASP. NET in essence? [ASP. NET operating mechanism]

After explaining the two major features of ASP. NET, you can basically fully answer what ASP. NET is.

ASP. NET is an ISAPI filter program of the host CLR.

The underlying Running Mechanism from ISAPI to ASP. NET to managed code is very complex. Here debuglzq is just a simple introduction:

  • ASP. NET initial run, load CLR.
  • IIS accepts an HTTP request and determines that the request should be bound to the ISAPI filter aspnet_filter.dll.
  • ASP.. Net starts to process the HTTP request and determines the website to which the request belongs. If it is the first request of the website, a new application domain is created to process the request, if you already have a request for this website, use the existing application domain to process the request.
  • When a website file is dynamically updated (after ASP. NET 2.0, a new DLL needs to be compiled for the 1.0 website update), the application domain of the website will be reloaded.
4. Conclusion This article belongs to debuglzq. For more information, see the source. If you think this blog post is helpful to you, please recommend and pay attention to debuglzq to share your progress ~

 

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.