这个是判断类 根据上下文中得到的 访问类型 。判断执行那个方法
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>