[Asp. Net] About IIS and Asp. Net pipelines and iisasp.net Pipelines

Source: Internet
Author: User
Tags erro msmq metabase

[Asp. Net] About IIS and Asp. Net pipelines and iisasp.net Pipelines

As an Asp. Net platform developer, it is very necessary to understand how IIS and Asp. Net are combined to execute our managed code and Asp. Net pipeline events.


This section

  • IIS 5.X
  • IIS 6
  • IIS 7 +
  • Integration Mode
  • Asp. Net Pipeline
  • HttpModule
  • HttpHandle


IIS 5.x

InetInfo.exe and W3SVC services

IIS 5.xis running in inetinfo.exe. One of the most important services in this process is the Windows Service named World Wide Web Hing Service (W3SVC.

The main functions of W3SVC include HTTP request listening, working process management, and configuration management (by loading related configuration information from Metabase.


Request resources (differentiate static and dynamic resources by extension)

Static files directly return the file content.

Dynamic Resources: Use the extension to find the corresponding ISAPI Dll from the Script Map of IIS.



ISAPI is the abbreviation of Internet Server API (Internet Server Application Programming Interface). It is the link between IIS and other applications.

ISAPI includes ISAPI Extension and ISAPI Filter


ISAPI Extension

Different types of Dynamic resources are not required, and different ISAPI extensions are available.

For example, Asp. Net (. aspx. asmx. svc) is aspnet_isapi.dll. Find the dll in the directory "% windir % \ Microsoft. NET \ Framework \ {version no.


ISAPI Filter

Filter allows you to view, modify, forward, or reject HTTP requests before they are actually processed. For example, IIS can use ISAPI filtering to Authentication requests ).


Request Asp. Net

If we request a Resource Based on ASP. NET:


IIS5 Deficiency


IIS6 Solution


In addition, in IIS6, create a new http listener: HTTP Protocol Stack (HTTP Protocol Stack, HTTP. SYS)

  • Continuous listening:Because HTTP. SYS is a network driver and is always running, it can respond to users' HTTP requests in a timely manner;
  • Better stability:HTTP. SYS runs in the operating system kernel mode and does not execute any user code. Therefore, it is not affected by Web applications, working processes, and IIS processes;
  • Data cache in kernel mode:If a resource is frequently requested, HTTP. SYS caches the response content, and the cached content can directly respond to subsequent requests. Because this is a cache based on the kernel mode, there is no switch between the kernel mode and the user mode, and the response speed will be greatly improved.



Request Asp. Net

Different from IIS5.X:

1. the W3SVC service creates a Workflow Based on the request.

2. aspnet_isapi.dll is loaded during workflow initialization.




IIS 7 +

W3SVC Service

Features of the W3SVC service in IIS6

  • HTTPRequest receipt:Receives HTTP requests listened to by HTTP. SYS;
  • Configuration Management:Load configuration information from Metabase to configure related components;
  • Process Management:Create, recycle, and monitor processes.

In IIS7, W3SVC is only responsible for the first function, and the remaining functions are handed over to WAS service management.


WAS Service

IIS7 introduces the Windows Process Activation Service (WAS), which processes both HTTP and non-HTTP requests.


In WAS, an important Interface is defined: the Listener Adapter Interface abstracts the requests listened by different protocol listeners.

WAS listens to the http requests of the W3SVC service and the TCP, Named Pipes, and MSMQ3 requests of the WCF Service.



The three invigilators and invigilators of wcf.pdf are defined in the program set smhost.exe. You can find the assembly in the following directory: % windir % \ Microsoft. NET \ Framework \ v3.0 \ Windows Communication Foundation.

SMHost.exe provides four important Windows Services:

  • NetTcpPortSharing:Provides TCP port sharing for WCF;
  • NetTcpActivator:Provides TCP-based activation requests for WAS, including TCP listeners and corresponding listening adapters;
  • NetPipeActivator:Provides a named pipeline listener and corresponding listener adapter for WAS;
  • NetMsmqActivator:Provides MSMQ-based activation requests for WAS, including MSMQ listeners and corresponding listening adapters.


Integration Mode

Disadvantages of traditional models

  • Repeated operations:There are some repeated operations between IIS and ASP. NET, such as identity authentication;
  • Dynamic files are inconsistent with static files:Because only ASP. NET Dynamic files (such. aspx ,. asmx ,. (svc. NET isapiinto the asp.netpipeline, and for a few static files (such as .html ,. xml ,. IIS directly responds to the request, ASP. some functions in the NET pipeline will not be used for these static file-based requests. For example, we want to apply the Forms authentication to requests based on image files;
  • IISDifficult to expand:IIS extensions are basically reflected in custom isapis, but this is not an easy task for most people. Because ISAPI is a Win32-based unmanaged API, it is not an application-oriented programming interface. What we usually want is to extend IIS by hosting code like defining ASP. NET's HttpModule and HttpHandler.


Integration Mode

In fact, the IIS7 integration mode enables users to write a module hosting code and insert the managed code into the IIS kernel code for parsing, so that you can precisely control arbitrary requests and achieve better scalability.

(Each static file also goes through the lifecycle event, and the execution efficiency will definitely decrease .)


Differences in configuration files

<! -- Traditional mode --> <system. web> <customErrors mode = "RemoteOnly"> <error statusCode = "404" redirect = "404.html"/> <error statusCode = "500" redirect = "erro.html"/> </ customErrors> <compilation debug = "true" targetFramework = "4.5"/> 


Asp. Net Pipeline








Functionally, HttpModule is equivalent to ISAPI Filter in IIS in ASP. NET. Before IIS delivers the received request to the corresponding ISAPI Extension, the registered ISAPI Filter intercepts the request first.

If HttpModule is equivalent to ISAPI Filter of IIS, we can say that HttpHandler is equivalent to ISAPI Extension of IIS. HttpHandler plays the final handler role of the request in ASP. NET.

When the request is transferred to ASP. after the. NET pipeline, the final HttpHandler object that is responsible for processing the request matches the request resource type. However, before Handler's official work, ASP. NET will first load and initialize all the configured HttpModule objects. During the initialization process, the HttpModule registers some functions to the corresponding event of the HttpApplication. In this case, the corresponding event will be triggered at a certain stage in the entire request processing lifecycle of the HttpApplication, event Handlers registered with HttpModule can also be executed.

All httpmodules implement the IHttpModule interface.

namespace System.Web{  public interface IHttpModule  {    void Init(HttpApplication context);    void Dispose();  }}


System-defined HttpModule

  • OutputCacheModule: Implements the Output Caching function;
  • SessionStateModule: The Session-based status is implemented on the stateless HTTP protocol;
  • WindowsAuthenticationModule + FormsAuthenticationModule: Three typical authentication methods are implemented: Windows Authentication and Forms authentication;
  • WCFModule: Enables Asp. Net to expand the WCF Service (System. ServiceModel. Activation. HttpModule)


Custom HttpMoudle





For requests of different resource types, ASP. NET loads different Handler for processing, that is, the Handler corresponding to. aspx page and. asmx web service is different.

All HttpHandler implement the IHttpHandler interface.

  public interface IHttpHandler  {    bool IsReusable { get; }    void ProcessRequest(HttpContext context);  }


HttpHandle defined by the System

Aspx file of WebForm: System. Web. UI. Page

Svc file of WCF: System. ServiceModel. Activation. HttpHandler

MVC: MVCHandle


Custom HttpHandle

Because Handle maps the specified Handle before and after PostMapRequestHandler and PostResolveRequestCache,

So we can register our Handle in the PostResolveRequestCache event.

After PreRequestHandlerExecute, our Handle. PR method will be called.





HttpApplication mainly has 19 events. You can access all events through any address and parameters on my website.

+? Pipe can view the trigger time of these events. For example: http://neverc.cn? Pipe

+? Pe can attach my website content: http://neverc.cn? Pe

Guess how to achieve the above results


Address: http://neverc.cnblogs.com/p/4807836.html

Reference: http://www.cnblogs.com/artech/archive/2009/06/20/1507165.html

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.