【.NET】Handler中使用反射分离代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/It_sharp/article/details/84643943
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        if (context.Request["ID"] != null)
        {
            string ID = context.Request["ID"].ToString();
            System.Reflection.MethodInfo method = this.GetType().GetMethod("Method"+ID);
            if (method != null)
            {
                method.Invoke(this, new object[] { context });
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    public void Method1(HttpContext context)
    {
        context.Response.Write("Hello1");
    }
    public void Method2(HttpContext context)
    {
        context.Response.Write("Hello2");
    }
}

https://imququ.com/post/four-ways-to-post-data-in-http.html

猜你喜欢

转载自blog.csdn.net/It_sharp/article/details/84643943
今日推荐