[C#] 纯文本查看 复制代码
//定义一个委托
private delegate void actionByMain(HttpContext context);
//定义一Key,Value的键值对,大家注意这里把委托放进去了
private static Dictionary<string, actionByMain> mainList = new Dictionary<string, actionByMain>();
public void ProcessRequest(HttpContext context)
{
string action = string.Empty;
if (string.IsNullOrEmpty(context.Request["action"]))
{
return;
}
action = context.Request["action"];
//先检查一下有没有这个action
if (mainList.ContainsKey(action))
{
mainList[action](context); return;
}
}
//添加action对应方法的列表 此方法为构造器
static void addMainList()
{
mainList.Add("post1", delegate(HttpContext context)
{
context.Response.Write("成功");
});
mainList.Add("post2", delegate(HttpContext context)
{
context.Response.Write("成功");
});
mainList.Add("post3", delegate(HttpContext context)
{
return;
});
}