ASP Web Application Quick Start for. NET (5)

Source: Internet
Author: User

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!


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.