application|web| Quick Start Create a custom HttpHandler
To customize a handler, you can perform IHttpHandler, and in Config.web file
Add class information to the httphandlers section of the The following example shows how to create a custom
HttpHandler, map all requests to "simplehandler.aspx":
Simplehandler
[] Click Run Program]
| [] View Source code]
Custom HttpHandler can be created by executing the IHttpHandler interface, which
There are only two methods. By calling IsReusable, an HTTP
Factory is able to query the handler (processor) to determine whether the same instance can be used for service
Multiple requests for service. The ProcessRequest method accepts the HttpContext instance as an argument. This
In the example, the request data is ignored and a constant string is sent to the client as a response.
Consider the following code written in VB, C #, and JScript three languages:
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 placing the compiled processor collection under the application/bin directory, we Can
Specifies that the processor class is on the requested target. Here, all
Requests for "simplehandler.aspx" will be routed to a solid of the Simplehandler class
For example, it lives in the name space Acme.simplehandler.
Conclusion
The above is explained by the principle and the example. NET ASP Web application concept and make
, we see how to achieve the goal with three different programming languages. You will find that we
is slowly touching. net of magical thought, comprehend. NET's shocking power. We have reason to
Faith, with such a powerful tool, developers will be more creative!
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.