Exemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            context.Response.Expires     = 0;
            string result = "false";

            try
            {
                if (bllCardCoupon.IsLogin)
                {
                    CurrentUserInfo = bllCardCoupon.GetCurrentUserInfo();
                }
                else
                {
                    resp.errcode = 1;
                    resp.errmsg  = "尚未登录";
                    context.Response.Write(Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
                //WebSiteOwner = bllCardCoupon.WebsiteOwner;
                //basePath = string.Format("http://{0}", context.Request.Url.Host);
                string action = context.Request["action"];
                //利用反射找到未知的调用的方法
                if (!string.IsNullOrEmpty(action))
                {
                    MethodInfo method = this.GetType().GetMethod(action, BindingFlags.NonPublic | BindingFlags.Instance); //找到方法BindingFlags.NonPublic指定搜索非公有方法
                    result = Convert.ToString(method.Invoke(this, new[] { context }));                                    //调用方法
                }
                else
                {
                    resp.errmsg = "action not exist";
                    result      = Common.JSONHelper.ObjectToJson(resp);
                }
            }
            catch (Exception ex)
            {
                resp.errcode = -1;
                resp.errmsg  = ex.ToString();
                result       = Common.JSONHelper.ObjectToJson(resp);
            }

            if (!string.IsNullOrEmpty(context.Request["callback"]))
            {
                //返回 jsonp数据
                context.Response.Write(string.Format("{0}({1})", context.Request["callback"], result));
            }
            else
            {
                //返回json数据
                context.Response.Write(result);
            }
        }