ASP Web Application Quick Start for. NET (4)
Objects within the scope of Application or Session
In the Global. asax file, we can use object tags to define static objects. These objects can be. NET Framework classes or classic COM components. It can be applied to any appinstance, session, or application. If an object applies to Appinstance, it indicates that the object is clearly an instance of HttpApplication and is not shared.
See the following example to define the scope of the object:
<Object id = "id" runat = "server" class = ". NET
Framework class Name "scope =" appinstance ">
<Object id = "id" runat = "server" progid = "Classic
COM ProgID "scope =" session "/>
<Object id = "id" runat = "server" classid = "Classic
COM ClassID "scope =" application "/>
What are HttpHandlers and factories (Http processor and factory)
ASP. NET provides a set of low-level request/response APIs. With these APIs, we can use the. NET Framework class to serve input HTTP requests. These are HTTPHandlers.
And Factories. HTTPHandlers and Factories can be said to be the hub of the ASP. NET Framework. Factories (factory) allocates each request to a handler, which then processes the request. The specific implementation step is to create a class that supports the System. Web. IHTTPHandler interface and execute the ProcessRequest () method. The processor is often useful when it does not require services extracted from a high-level page framework to process HTTP requests. The general purposes of a processor include filters and CGI-like applications, especially those that return binary data.
Each HTTP input request received by ASP. NET is finally processed by IHTTPHandler, a special class instance. IhttpHandlerFactory provides a processor to the underlying lower part of the IHTTPHandler instance. ASP. NET comes with three standard IhttpHandlerFactory classes: PageHandlerFactory, RestrictedResourceFactory, and WebServiceHandlerFactory. We can also choose to create and register additional factories (factory) to support richer request decisions and activation scenarios.
Configure HttpHandlers and Factories
HTTPHandlers and factories are configured as part of the config. web file. ASP. NET defines an "httphandlers" configuration section, where you can add and delete HTTPHandlers and factories. These configuration information can be inherited through sub-directories.
For example, the following code is located in the header of the config. web file to map all requests about the. aspx file to the PageHandlerFactory class:
<Httphandlers>
...
<Add verb = "*" path = "*. aspx" type = "System. Web. UI. PageHandlerFactory"
/>
...
</Httphandlers>