ASP Web Application Quick Start for. NET (5)
Create a custom HttpHandler
To customize a handler, You can execute IhttpHandler and add class information in the httphandlers section of the config. web file. The following example shows how to create a custom HttpHandler and map all requests to "SimpleHandler. aspx:
SimpleHandler
[] <A href = http://www.aspnextgen.com/quickstart/aspplus/samples/apps/handler/vb/simplehandler.aspx> click to run the program </a>]
| [] <A href = http://www.aspnextgen.com/quickstart/util/srcview.aspx? Path =/quickstart/aspplus/samples/apps/handler. src> View Source Code </a>]
Custom HttpHandler can be created by executing the IhttpHandler interface, which has only two methods. By calling IsReusable, an HTTP
Factory can query handler (processor) to determine whether the same instance can be used to serve multiple requests. The ProcessRequest method accepts the HttpContext instance as a parameter. In this example, the request data is ignored, and a constant string is sent to the client as a response. See the following code written in three languages: VB, C #, and JScript:
C #
Public class SimpleHandler: IHttpHandler {
Public void ProcessRequest (HttpContext context ){
Context. Response. Write ("Hello World! ");
}
Public bool IsReusable (){
Return true;
}
}
VB
Public Class SimpleHandler: Inherits IHttpHandler
Public Sub ProcessRequest (context As HttpContext)
Context. Response. Write ("Hello World! ")
End Sub
Public Function IsReusable () As Boolean
Return (True)
End Function
End Class
JScript
Public class SimpleHandler implements IHttpHandler {
Public function ProcessRequest (context: HttpContext): void {
Context. Response. Write ("Hello World! ");
}
Public function IsReusable (): Boolean {
Return true;
}
}
After the compiled processor set is placed under the/bin directory of the application, we can specify the processor class to the request target. All requests to "SimpleHandler. aspx" will be routed to an instance of the SimpleHandler class, which will survive in the namespace Acme. SimpleHandler.
Knot
The Principles and Examples above describe the concept and usage of ASP Web Application in. NET. We can see how to use three different programming languages to achieve the goal. You will find that we are slowly tapping into the magical idea of. NET and understanding the shocking power of. NET. We have reason to believe that with such powerful tools, developers will be more creative!