How to: Register HTTP Handlers

After you have created a custom HTTP handler class, you must register it in the Web.config file. This enables ASP.NET to call the HTTP handler in order to service requests for resources that have the specified file name extension.

How you register an HTTP handler depends on the version of Internet Information Services (IIS) that hosts your application. For IIS 6.0, you register the handler by using the httpHandlers section of the Web.config file. For IIS 7.0 running in Classic mode, you register the handler in the httpHandlerssection, and you map the handler to the Aspnet_isapi.dll file. For IIS 7.0 running in Integrated mode, you register the handler by using the handlerselement in the system.WebServer section.

To register an HTTP handler for IIS 6.0

  1. Compile the HTTP handler class and copy the resulting assembly to the Bin folder under the application's root folder.

    -or-

    Put the source code for the handler into the application's App_Code folder.

    For an example of an HTTP handler, see Walkthrough: Creating a Synchronous HTTP Handler.

  2. In the application's Web.config file, create an httpHandlers section.

    The following example shows how to register an HTTP handler that responds to requests for the SampleHandler.new resource. The handler is defined as the class SampleHandler in the assembly SampleHandlerAssembly.

     
     
    <configuration>
    <system.web>
    <httpHandlers>
    <add verb="*" path="SampleHandler.new"
    type="SampleHandler, SampleHandlerAssembly" />
    </httpHandlers>
    </system.web>
    </configuration>

    The following example maps all HTTP requests for files that have the file name extension ".SampleFileExtension" to the SampleHandler2 class. In this case, the handler code is in the App_Code folder, so you do not have to specify an assembly.

     
     
    <configuration>
    <system.web>
    <httpHandlers>
    <add verb="*" path="*.SampleFileExtension"
    type="SampleHandler2 " />
    </httpHandlers>
    </system.web>
    </configuration>
  3. Configure IIS to forward the request for the custom file name extension to ASP.NET.

    For more information, see How to: Configure an HTTP Handler Extension in IIS.

To register an HTTP handler for IIS 7.0 running in Classic mode

  1. Compile the HTTP handler class and copy the resulting assembly to the Bin folder under the application's root folder.

    -or-

    Put the source code for the handler into the application's App_Code folder.

    For an example of an HTTP handler, see Walkthrough: Creating a Synchronous HTTP Handler.

  2. In the application's Web.config file, create an httpHandlers section.

  3. Create a system.webServer section inside the configuration element.

      1. Create a handlers element inside the system.WebServer section.

         Note

        You must define both an httpHandlers element and a handlers element.

        The following example shows how to register an HTTP handler that responds to requests for the SampleHandler.new resource. The handler is defined as the class SampleHandler in the assembly SampleHandlerAssembly.

         
         
        <configuration>
        <system.web>
        <httpHandlers>
        <add verb="*" path="SampleHandler.new"
        type="SampleHandler, SampleHandlerAssembly" />
        </httpHandlers>
        </system.web>
        <system.webServer>
        <handlers>
        <add name="TestLip" path="*.lip" verb="*"  modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
         </handlers>
        </system.webServer>
        </configuration>

        Replace FrameworkPath with the correct path to the Aspnet_isapi.dll file.

        The following example maps all HTTP requests for files that have the file name extension ".SampleFileExtension" to the SampleHandler2 class. In this case, the handler code is in the App_Code folder, so you do not have to specify an assembly.

         
         
        <configuration>
        <system.web>
        <httpHandlers>
        <add verb="*" path="*.SampleFileExtension"
        type="SampleHandler2" />
        </httpHandlers>
        <system.web>
        <system.webServer>
          
        <handlers>
        <add name="TestLip" path="*.lip" verb="*"  modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
         </handlers>
        </system.webServer> </configuration>

        Replace FrameworkPath with the correct path to the Aspnet_isapi.dll file.

        Note

        For IIS 7.0 running in Classic mode, you do not have to separately use IIS Manager to map the file name extension to the Aspnet_isapi.dll file, as you do with IIS 6.0. You can map the extension in the Web.config file.

To register an HTTP handler for IIS 7.0 running in Integrated Mode

  1. Compile the HTTP handler class and copy the resulting assembly to the Bin folder under the application's root folder.

    -or-

    Put the source code for the handler into the application's App_Code folder.

    For an example of an HTTP handler, see Walkthrough: Creating a Synchronous HTTP Handler.

  2. In the application's Web.config file, create a handlers element in the system.webServer section.

     Note

    Handlers that are defined in the httpHandlers element are not used. If you do not remove the httpHandlers registrations, you must set the validation element’s validateIntegratedModeConfiguration attribute to false in order to avoid errors. The validation element is a child element of the system.webServer element. For more information, see "Disabling the migration error message" in ASP.NET Integration with IIS 7.0.

    The following example shows how to register an HTTP handler that responds to requests for the SampleHandler.new resource. The handler is defined as the class SampleHandler in the assembly SampleHandlerAssembly.

     
     
    <configuration>
    <system.webServer>
    <handlers>
    <add name="SampleHandler" verb="*"
    path="SampleHandler.new"
    type="SampleHandler, SampleHandlerAssembly"
    resourceType="Unspecified" />
    </handlers>
    </system.webServer>
    </configuration>
    Note

    The resourceType attribute performs the same function as the Verify file exists option in IIS manager for IIS 6.0.

    The following example shows how to map all HTTP requests to files with the file name extension ".SampleFileExtension" to the SampleHandler2HTTP handler class. In this case, the handler code is in the App_Code folder, so you do not have to specify an assembly.

     
     
    <configuration>
    <system.webServer>
    <handlers>
    <add name="SampleHandler2" verb="*"
    path="*.SampleFileExtension"
    type="SampleHandler2" />
    resourceType="Unspecified" />
    <handlers>
    </system.webServer>
    </configuration>

    For IIS 7.0 running in Integrated mode, only the registration in the handlers element is required.

    For more information about the IIS web.webServer configuration element, see system.webServer Section Group (IIS Settings Schema) on the MSDN Web site.

    For more information about how to configure a handler for a custom file name extension, see How to: Configure an HTTP Handler Extension in IIS.

注册HttpHandler的更多相关文章

  1. webconfig中注册HttpHandler报错:检测到在集成的托管管道模式下不适用的 ASP.NET 设置。

    为什么会出现以上错误? 在IIS7的应用程序池有两种模式,一种是"集成模式",一种是"经典模式". 经典模式 则是我们以前习惯的IIS 6 的方式. 如果使用集 ...

  2. (转)HttpHandler与HttpModule的理解与应用

    神秘的HttpHandler与HttpModule 大学时候我是从拖控件开始学习 asp.net的,对.net的很多类库对象都不是很了解.所以看到大家写一些个性的asp.net名词,就感觉asp.ne ...

  3. HttpHandler与HttpModule介绍

    前言:作为一个开发人员,我们看过很多的关于开发的书,但是都是教我们"知其然",并没有教我们"知其所以然",我们开发web项目的过程中,当我们输完URL敲下回车就 ...

  4. ASP.NET页面生存周期

    .Net的Page请求过程:

  5. FastRPC 3.2 发布,高性能 C++ 协程 RPC 框架

    用过go erlang gevent的亲们应该都会知道协程在应用中带来的方便. 如果对协程不理解的同学,通过阅读下面例子可以快速了解我们框架的协程的意义,已了解的可以跳过这部分. 协程例子:假设我们要 ...

  6. ASP.NET管道模型简析

    我相信在第一次听到这个名词时,有的小伙伴会一脸懵,而且还有很多疑问,其实我在第一次接触这个概念时跟很多小伙伴一样一脸懵. 接下来我将以我自己的理解来讲述什么是管道模型. 什么是管道模型 首先有没有小伙 ...

  7. ASP.NET Core的路由[1]:注册URL模式与HttpHandler的映射关系

    ASP.NET Core的路由是通过一个类型为RouterMiddleware的中间件来实现的.如果我们将最终处理HTTP请求的组件称为HttpHandler,那么RouterMiddleware中间 ...

  8. 注册URL模式与HttpHandler的映射关系

    注册URL模式与HttpHandler的映射关系 ASP.NET Core的路由是通过一个类型为RouterMiddleware的中间件来实现的.如果我们将最终处理HTTP请求的组件称为HttpHan ...

  9. httphandler和httpmodule的区别

    ASP.Net处理Http Request时,使用Pipeline(管道)方式,由各个HttpModule对请求进行处理,然后到达 HttpHandler,HttpHandler处理完之后,仍经过Pi ...

随机推荐

  1. 【Spring源码解析】—— 简单工厂模式的BeanFactory的超简版实现

    一.什么是简单工厂模式 设计模式的核心是“分工”,通过分工将对象与职责划分的更细化,进而提升系统设计的可扩展性,使其更容易维护. 开闭原则:对扩展开放,对修改关闭:要增加一个新的处理逻辑,可以开一个新 ...

  2. Find Median from Data Stream - LeetCode

    Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...

  3. jeesite导入数据库错误:java.sql.SQLException: Incorrect string value: '\xE4\xB8\xAD\xE5\x9B\xBD' for column 'name' at row 1问题解决

    如果使用mvn antrun:run -Pinit-db进行数据库导入导致出现如下错误: 解决方法: 这个是由于新建数据库没有选择默认字符集导致的,只要选择utf-8即可.

  4. Linux基础学习5

    程序管理与SELinux初探 process&program  程序 (program):通常为 binary program ,放置在储存媒体中 (如硬盘.光盘.软盘.磁带等), 为实体档案 ...

  5. 【DQ冰淇淋】—— Babylon 冰淇淋三维互动营销项目总结

    前言:在学习过Babylon.js基础之后,我上手的第一个网页端3D效果制作项目就是‘DQ冰淇淋’.这个小项目应用到了Babylon最基础的知识,既可以选味道,选点心,也可以旋转.倒置冰淇淋,互动起来 ...

  6. C#反射获取属性值和设置属性值

    /// /// 获取类中的属性值 /// public string GetModelValue(string FieldName, object obj) { try { Type Ts = obj ...

  7. 如何选择Haproxy和Nginx

    对于做软负载,我们都知道主流的方案有LVS.Haproxy.Nginx!那么对于Haproxy和Nginx,我们如何选择呢?回答这个问题之前,我根据个人使用经验来讲下它们的特点! Haproxy特点 ...

  8. PGM图片格式与代码

    这两天在搞神经网络,里面的一个人脸数据库的图片格式是PGM,事实上之前早就知道了这个图片格式,可是没去深究这个图片格式的数据究竟是什么安排的.搜索了下百度百科,发现介绍的真是简单,以下就自己来系统地整 ...

  9. Win7如何修复开机画面

    将下面文件保存为"修复Win7开机画面.bat"双击运行即可   bcdedit /set {current} locale zh-CN    

  10. 性能指标 - OEE

    work center 是指 执行制造作业的资源, 可以是 一个人, 一组人, 一台自动机器, 一组自动机器, 一个半自动机器, 一组半自动机器, 或者是 一个区域组成的生产资源 基本参数 Time ...