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.

  • 相关阅读:
    网页打开本地exe程序
    【JS】最简单的域名防红方法,QQ/微信打开网站提示浏览器打开
    【HTML】建站成功默认页面
    python中日志器的使用
    python中连接mysql
    python中处理配置文件
    接口实战项目总结上
    布隆过滤器和LRU Cache
    Python版常见的排序算法
    LeetCode 27. 移除元素
  • 原文地址:https://www.cnblogs.com/lip-blog/p/7264269.html
Copyright © 2011-2022 走看看