<%@ 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");
}
}
【.NET】Handler中使用反射分离代码
最新推荐文章于 2024-06-28 13:34:22 发布
本文介绍了一种使用ASP.NET WebHandler进行动态方法调用的技术,通过读取HTTP请求参数来决定调用哪个方法,实现了灵活的响应处理。此方法允许基于传入的ID参数动态选择并执行不同的后台处理逻辑。
53

被折叠的 条评论
为什么被折叠?



