zoukankan      html  css  js  c++  java
  • [置顶] 判断用户的请求类型 get or post 然后同步 或者 异步 执行 方法

       这个是判断类 根据上下文中得到的 访问类型 。判断执行那个方法

    using System;
    using System.Web;
    
    class HandlerFactory : IHttpHandlerFactory
    {
        public IHttpHandler GetHandler(HttpContext context, 
            string requestType, String url, String pathTranslated)
        {
            IHttpHandler handlerToReturn;
            if ("get" == context.Request.RequestType.ToLower())
            {
                handlerToReturn = new HelloWorldHandler();
            }
            else if ("post" == context.Request.RequestType.ToLower())
            {
                handlerToReturn = new HelloWorldAsyncHandler();
            }
            else
            {
                handlerToReturn = null;
            }
            return handlerToReturn;
        }
        public void ReleaseHandler(IHttpHandler handler)
        {
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    
    
    在执行这个类的时候,首先要在web.config中添加一个节点
    <configuration>
      <system.web>
        <httpHandlers>      <add verb="GET,POST" path="*.sample"        type="HandlerFactory" />    </httpHandlers>
      </system.web>
    </configuration>

    
    

    遇见了就不要错过
  • 相关阅读:
    游记&退役记
    Nothing to say
    学习知识点的比较好的blog
    计划做题列表
    后缀自动机小专题
    复数
    FFT学习
    P2900 [USACO08MAR]土地征用Land Acquisition
    # 数位DP入坑
    Hdu 4035 Maze(概率DP)
  • 原文地址:https://www.cnblogs.com/Traner/p/2819998.html
Copyright © 2011-2022 走看看