Introduction
The low level Request and Response API to service incoming Http requests are Http Handlers in Asp.Net. All handlers implement the IHttpHandler interface, which is located in the System.Web namespace. Handlers are somewhat analogous to Internet Server Application Programming Interface (ISAPI) extensions.
In this article, I will explain how to extend the functionality of web server by using Http handlers and How to protect files using Http handlers.
Methods in Http Handler
The following are the methods in Http Handlers
Method Name Description
ProcessRequest Used to 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
Creating HTTP Handlers
To create an HTTP handler, you must implement the IHttpHandler interface. The IHttpHandler interface has one method and one property with the following signatures:
void ProcessRequest(HttpContext);
bool IsReusable {get;}
Customized Http Handler
By customizing http handlers, new functionalities can be added to Web Server. Files with new extensions like .text for a text file can be handled by Web Server by using http handlers. The future of customization can lead to hosting .jsp pages in IIS by finding adequate ISAPI extensions. The following steps are involved to create customized http handler:
Create a C# class library as "Examplehandler"
Name class as "Handlerclass.cs"
using System;
using System.Web;
using System.Web.SessionState;
namespace ExampleHandler
{
///
/// Summary description for Examplehandler.
///
public class Handlerclass : IHttpHandler
{
public Handlerclass()
{
//
// TODO: Add constructor logic here
//
}
#region Implementation of IHttpHandler
public void ProcessRequest(System.Web.HttpContext context)
{
HttpResponse objResponse = context.Response ;
HttpSessionState objSession = context.Session ;
objResponse.Write("
No comments:
Post a Comment