1. 程式人生 > >【.NET】Handler中使用反射分離程式碼

【.NET】Handler中使用反射分離程式碼

<%@ 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