zoukankan      html  css  js  c++  java
  • 注册HttpHandler

    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 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.NETFramework64v2.0.50727aspnet_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.NETFramework64v2.0.50727aspnet_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.

          NoteNote

          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 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>
      
      NoteNote

      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.

  • 相关阅读:
    cnpm 下载
    WebSocket协议 8 问
    ECMAScript6笔记
    js-scroll判断页面是向上滚动还是向下滚动
    JS高级. 06 缓存、分析解决递归斐波那契数列、jQuery缓存、沙箱、函数的四种调用方式、call和apply修改函数调用方法
    JS高级. 05 词法作用域、变量名提升、作用域链、闭包
    JS高级. 04 增删改查面向对象版歌曲管理、递归、
    JS高级. 03 混入式继承/原型继承/经典继承、拓展内置对象、原型链、创建函数的方式、arguments、eval、静态成员、实例成员、instanceof/是否在同一个原型链
    【Semantic Segmentation】U-Net: Convolutional Networks for Biomedical Image Segmentation 论文解析(转)
    【Semantic segmentation Overview】一文概览主要语义分割网络(转)
  • 原文地址:https://www.cnblogs.com/lip-blog/p/7264269.html
Copyright © 2011-2022 走看看