For example: Output xmlDom, logout and jump, there is no html output, it is very troublesome, you need to create a page, delete unnecessary html, and write processing code in page_load. The use of HttpHandler does not need to be so troublesome.
You can use any language that complies with common language standards (CLS) to write custom HTTP handlers to process specific and predefined types of HTTP requests. The executable code defined in the HttpHandler class is used to respond to these specific requests, rather than the conventional ASP or ASP. NET Web pages. The HTTP processing program provides you with a way to interact with low-level requests and Response Services of the IIS Web server. It also provides functions that are very similar to ISAPI extensions but simple programming models.
For example, I need to implement a Logout. aspx page to log out and jump to. The following example mainly responds to the client's request for a page named logout. aspx to log out and jump. All requests to logout. aspx are provided by LogoutHttpHandler in WebUC. HttpHandler, The namespace in WebUC. dll of the Assembly.
Modify web. config and add the following script to <system. web> </system. web>:
<HttpHandlers>
<Add verb = "GET" path = "Logout. aspx" type = "WebUC. HttpHandler. LogoutHttpHandler, WebUC"/>
</HttpHandlers>
Among them, WebUC. HttpHandler. LogoutHttpHandler is the class for implementing the Logout. aspx function. WebUC is the dll of my web project. (For details, refer to msdn)
The following is the code of LogoutHttpHandler. It inherits the excuse to rewrite methods and attributes.
Copy codeThe Code is as follows:
Using System;
Using System. Web;
Using System. Web. Caching;
Using System. Web. Security;
Namespace WebUC. HttpHandler
{
Public class LogoutHttpHandler: IHttpHandler
{
/// <Summary>
/// Enable HTTP Web request processing by implementing the custom HttpHandler interface of the IHttpHandler interface.
/// </Summary>
/// <Param name = "context"> HttpContext object, which provides reference for internal Server objects (such as Request, Response, Session, and Server) used to provide services for HTTP requests. </Param>
Public void ProcessRequest (HttpContext context)
{
FormsAuthentication. SignOut ();
Context. Response. Redirect ("Login. aspx", true );
}
/// <Summary>
/// Obtain a value indicating whether other requests can use the IHttpHandler instance.
/// </Summary>
Public bool IsReusable
{
Get
{
Return false;
}
}
}
}
}
After compilation, I can directly use http: // ***/logout. aspx is used to log out. In fact, there is no logout in my web directory. the aspx file can also be used in many aspects, such as preventing leeching and downloading statistics.