统一接口调用

来源:互联网 发布:安卓手机优化软件 知乎 编辑:程序博客网 时间:2024/05/18 06:20
<%@ WebHandler Language="C#" Class="Default" %> using System;using System.Web;using System.Collections.Generic; public class Default: IHttpHandler{     private static Dictionary<string, IHttpHandler> dic = new Dictionary<string, IHttpHandler>();     static TestCommand()    {        dic.Add("user.get", new GetUser());    }     public void ProcessRequest(HttpContext context)    {        var cmd = context.Request.QueryString["method"];        IHttpHandler handler;        if (!dic.TryGetValue(cmd, out handler))        {            context.Response.StatusCode = 404;            return;         }         if (!handler.IsReusable)            handler = (IHttpHandler)Activator.CreateInstance(handler.GetType());        handler.ProcessRequest(context);    }     public bool IsReusable    {        get        {            return false;        }    } }

阅读全文
0 0
原创粉丝点击