Download:Examplehandler.rar 3Kb
Introduction The low level Request and Response APIs to service incoming HTTP requests are HTTP handlers in asp.net. All handlers implement the IHttpHandler interface, which are located in the System.Web namespace. Handlers are somewhat analogous to Internet Server application Programming (ISAPI) Interface.
In this article, I'll explain how to extend the functionality of Web server by using Http handlers and how to protect fi Les using Http handlers. Methods in Http Handler
The following are the methods in Http handlers.
| Method Name |
Description |
| ProcessRequest |
Used o call Http Requests. |
| IsReusable |
To check the reusability of same instance handler with a new request of same type. |
Configuring HTTP Handlers The Administrators Use the <add> tag directive to configure the
<add verb= "[verb list]" path= "[Path/wildcard]" type= "[COM + Class], [Assembly]" validate= "[True/false]"/> <remove verb= "[verb list]" path= "[Path/wildcard]"/> <clear/> |
Creating HTTP Handlers To create a HTTP handler, you must implement the IHttpHandler interface. The IHttpHandler interface has one method and the following signatures: void ProcessRequest (Httpcont EXT); bool IsReusable {get;} Customized HTTP Handler by customizing HTTP handlers, new functionalities can is added to Web Server. The Files with the new extensions like. Text for a text file can is handled by the Web Server by using HTTP handlers. The future of customization can leads to hosting. JSP pages in IIS by finding adequate ISAPI extensions. The following steps are involved to create customized HTTP handler: 1. Create a C # class library as 揈 XAMPLEHANDLER?BR&G T 2. Name class as 揌 andlerclass.cs?/font>
using System; Using System.Web; using System.Web.SessionState; Namespace Examplehandler { ///<summary> ///Summary description for Examplehandler. </summary> public class Handlerclass:ihttphandler { Public handlerclass () { // //TODO: Add constructor logic here // } #region Implementation of IHttpHandler public void ProcessRequest ( System.Web.HttpContext context) { HttpResponse the Objresponse = context. Response; HttpSessionState objsession = context. session; Objresponse.write (" Objresponse.write ("</body>} public bool isreusable { Get { return true; } } #endregion } } |
Compile it and place it in the bin directory of TESTAPP project.
Step 2
Register this handler by adding the following text in the Web.config file:
<add verb= "*" path= "*.text" type= "Examplehandler.handlerclass, Examplehandler"/> |
Step 3 Go to Internet information Services and select Default Web Site. Right Click and Select Properties. Select Home Directory and click on Configuration. The following screen would appear:
Click on Add and give executable path and new extension and click OK.
Close IIS and Run TestApp website by using the URL
Http://localhost/Testapp/hello.text
The output would be as follows:
HttpForbiddenHandler The sensitive files can be protected by Http forbidden Handler. The Database driven Web sites using MS Access, the. mdb file has to is protected. To protect the. mdb files, we must follow the two steps given below:
1. Map. mdb file in IIS
2. Register the file extension in Web.config with HttpForbiddenHandler.
In the Web.config file, Add this Http handler section:
<add verb= "*" path= "*.mdb" type= "System.Web.HttpForbiddenHandler"/> |
ConclusionThe Http handlers are often useful when the "services provided by" High-level page framework abstraction are not require D for processing the HTTP request. Common uses of handlers include filters and cgi-like applications, especially those that return binary data. |