コード例 #1
0
        /// <summary>
        /// 应用程序认证请求
        /// </summary>
        /// <param name="sender">发送对象</param>
        /// <param name="e">事件参数</param>
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication app      = (HttpApplication)sender;
            string          username = string.Empty;

            if (app.Context.User != null && app.Context.User.Identity != null)
            {
                username = app.Context.User.Identity.Name;
            }
            int w = 0;
            int h = 0;

            if (app.Context.Request["nfm"].ObjToInt() == 1)
            {
                username = app.Context.Request["un"].ObjToStr(); //请求中自带的用户名
                w        = app.Context.Request["w"].ObjToInt();
                h        = app.Context.Request["h"].ObjToInt();
            }
            if (!string.IsNullOrEmpty(username))
            {
                UserInfo tempUserInfo = UserInfo.GetCurretnUser(app.Context);
                if (tempUserInfo == null || tempUserInfo.UserId == Guid.Empty || tempUserInfo.UserName.ToLower() != username.ToLower())
                {
                    Guid     userId   = UserOperate.GetUserIdByUserName(username);
                    UserInfo userInfo = UserOperate.GetUserInfo(userId);
                    if (w > 0 && h > 0)
                    {
                        userInfo.ClientBrowserWidth  = w;
                        userInfo.ClientBrowserHeight = h;
                    }
                    //缓存用户扩展信息
                    UserInfo.CacheUserExtendInfo(userInfo.UserName, userInfo.ExtendUserObject);
                    //保存票据
                    FormsPrincipal.Login(userInfo.UserName, userInfo, UserInfo.ACCOUNT_EXPIRATION_TIME, app.Context);
                }
                FormsPrincipal.TrySetUserInfo(app.Context);
            }
            else
            {
                FormsPrincipal.TrySetUserInfo(app.Context);
            }
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: tigerphz/TMallSolution
        public void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            FormsPrincipal <UserInfo> .TrySetUserInfo(app.Context);
        }