转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
HTTP Handlers in ASP.NET         ★★★★

HTTP Handlers in ASP.NET

作者:闵涛 文章来源:闵涛的学习笔记 点击数:897 更新时间:2009/4/23 10:39:21
HTTP Handlers in ASP.NET HTTP Handlers in ASP.NETAuthorDate Of SubmissionUser LevelSivakumar N08/24/2004Intermediate
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 NameDescriptionProcessRequestUsed o call Http Requests.IsReusableTo check the reusability of same instance handler with a new request of same type.
Configuring HTTP Handlers

The <httpHandlers> configuration section handler is responsible for mapping incoming URLs to the IHttpHandler or IHttpHandlerFactory class. It can be declared at the computer, site, or application level. Subdirectories inherit these settings.

Administrators use the <add> tag directive to configure the <httpHandlers> section. <Add> directives are interpreted and processed in a top-down sequential order. Use the following syntax for the <httpHandler> section handler:

<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 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:
1. Create a C# class library as 揈xamplehandler?br> 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 objResponse = context.Response ;
HttpSessionState objSession = context.Session ;
objResponse.Write("<html><body><h1>Hello World from Handler") ;
objResponse.Write("</body></html>") ;
}

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, the .mdb file has to be 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:

<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 abstraction are not required for processing the HTTP request. Common uses of handlers include filters and CGI-like applications, especially those that return binary data.

The Http Handlers are often useful when the services provided by the high-level page framework abstraction are not required for processing the HTTP request. Common uses of handlers include filters and CGI-like applications, especially those that return binary data.


本文引用通告地址: http://blog.csdn.net/jabby12/services/trackbacks/102211.aspx
[点击此处收藏本文] 发表于 2004年09月12日 7:55 PM

需要有评价卡才可以评价。评价卡获得帮助

david 发表于2005-06-24 6:28 PM  Great!


[Web开发]关于虚拟空间的System.Web.HttpUnhandledExceptio…  [网页制作]apache与http错误代码总结
[网页制作]很有意义的网页制作之meta标签中的name、http-equ…  [办公软件]PowerPoint模板使用经验之谈
[办公软件]教你在Powerpoint中设置页眉页脚  [办公软件]在Powerpoint中如何插入Flash动画
[办公软件]如何在Powerpoint 中(实现)输入上标、下标  [办公软件]如何在PowerPoint同一张幻灯片中显示大量文字
[办公软件]这样来修改PowerPoint超级链接的文字颜色  [办公软件]PowerPoint小小操作技巧,让您工作更轻松
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台