예제 #1
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            //try
            //{
            //	if (HttpContext.Current != null && SessionHelper["UserInfo"] == null)
            //	{
            //		var obj = new ReturnMessage { success = false, message = "not authed." };
            //		var json = JsonHelper.Serialize(obj);
            //		HttpContext.Current.Response.Write(json);
            //		actionContext.Response = new HttpResponseMessage { StatusCode = System.Net.HttpStatusCode.OK };
            //	}
            //}
            //catch (Exception ex)
            //{

            //}

            if (IsTestMode() && SessionHelper["UserInfo"] == null)
            {
                var ubll = new Wx.BLL.UserBLL();
                SessionHelper["UserInfo"] = ubll.FromDbUser(ubll.TestUser);
            }

            if (HttpContext.Current != null && SessionHelper["UserInfo"] == null)
            {
                base.OnAuthorization(actionContext);
            }
        }
예제 #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var actionFilter = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AllowAnonymousAttribute), false);

            if (!actionFilter.Any())
            {
                //filterContext.Controller.ControllerContext.HttpContext.Response.Write("FLL");
                var Request  = HttpContext.Current.Request;
                var Response = HttpContext.Current.Response;
                var Session  = HttpContext.Current.Session;

                if (IsTestMode() && SessionHelper["UserInfo"] == null)
                {
                    var ubll = new Wx.BLL.UserBLL();
                    SessionHelper["UserInfo"] = ubll.FromDbUser(ubll.TestUser);
                }
                else if (SessionHelper["UserInfo"] == null)
                {
                    var redirect = Request.Url.ToString();//.Replace(Request.Url.Authority, ConfigurationManager.AppSettings["UserInfoCallbackDomain"]);
                    var callback = "http://" + ConfigurationManager.AppSettings["UserInfoCallbackDomain"] + "/oauth2/UserInfoCallback/?redirect=" +
                                   HttpContext.Current.Server.UrlEncode(redirect);
                    //callback += "&inviteUid=" + uid;
                    var authUrl = OAuthApi.GetAuthorizeUrl(appId, callback, "JeffreySu", OAuthScope.snsapi_userinfo);
                    //Response.Write(string.Format("<a href={0}>{1}</a>", authUrl, HttpContext.Current.Server.UrlDecode(authUrl)));
                    //System.Threading.Thread.Sleep(200);
                    var redirectCount = int.Parse((Session["RedirectCount"] ?? 0).ToString());
                    if (redirectCount > 20)
                    {
                        System.IO.File.AppendAllLines(@"D:\\log.txt", new string[] { string.Format("auth rd:{0}", Request.QueryString["redirect"]) });
                        Response.Write("Reach Max Redirect Count!");
                        return;
                    }
                    Session["RedirectCount"] = redirectCount + 1;
                    Response.Redirect(authUrl);
                    //Response.Write(authUrl);
                    return;
                }
                Session["RedirectCount"] = 0;
            }
            ;


            base.OnActionExecuting(filterContext);
        }