HTTP handlers in ASP. NET

Source: Internet
Author: User
HTTP handlers in ASP. NET
Author Date of submission User level
Sivakumar n 08/24/2004 Intermediate


Download:Examplehandler.rar 3kb

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 o call HTTP requests.
Isreusable To check the reusability of same instance handler with a new request of same type.


Processing HTTP handlers

The

Administrators use the <add> tag directive to configure the

<Httphandlers>
<Add verb = "[verb list]" Path = "[path/wildcard]" type = "[COM + class], [Assembly] "Validate =" [true/false] "/>
<Remove verb = "[verb list]" Path = "[path/wildcard]"/>
<Clear/>
</Httphandlers>


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 mizmizing 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 mizmization can lead 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 your xamplehandler? BR> 2. Name class as your 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 objresponse = context. response;
Httpsessionstate objsession = context. Session;
Objresponse. Write ("<HTML> <body> 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:

<Httphandlers>
<Add verb = "*" Path = "*. Text" type = "examplehandler. handlerclass, examplehandler"/>
</Httphandlers>


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 will 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 will be as follows:

Httpforbiddenhandler

The sensitive files can be protected by HTTP forbidden handler. the database driven web sites using MS access,. MDB file has to be protected. to protect. 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:

<Httphandlers>
<Add verb = "*" Path = "*. mdb" type = "system. Web. httpforbiddenhandler"/>
</Httphandlers>


Conclusion

The HTTP handlers are often useful when the services provided by the High-Level page framework provided action are not required for processing the HTTP request. common uses of handlers include filters and CGI-like applications, especially those that return binary data.

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.