Esempio n. 1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            // 模拟数据库验证通过
            string uName = txtName.Text.Trim();
            string uPwd = txtPwd.Text.Trim();
            if (uName == uPwd)
            {
                // 创建登录凭证
                UserInfo user = new UserInfo();
                user.Alias = uName;
                user.HTTP_USER_AGENT = Request.UserAgent;
                user.UserIp = Request.UserHostAddress;
                user.ExpireDate = DateTime.Now.AddMinutes(double.Parse(System.Configuration.ConfigurationManager.AppSettings["CookieTimeout"]));
                string token = Guid.NewGuid().ToString("N").ToUpper();
                CacheManager.InsertToken(token, user);

                // 设置主站cookie
                HttpCookie cookie = new HttpCookie("Passport.Token");
                cookie.Value = token;
                cookie.Domain = "www.passport.com";
                //cookie.Domain = "localhost";
                cookie.Expires = DateTime.Now.AddMinutes(double.Parse(System.Configuration.ConfigurationManager.AppSettings["CookieTimeout"]));
                Response.AppendCookie(cookie);

                // 跳转回来访页面或OA平台主页
                if (Request.QueryString["BackUrl"] != null)
                {
                    Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["BackUrl"]) + "?Token=" + token);
                }
                else
                {
                    Response.Write("返回OA平台系统!");
                }
            }
        }
Esempio n. 2
0
 public static void InsertToken(string token, UserInfo user)
 {
     if (HttpContext.Current.Cache["PASSPORT.TOKEN"] == null)
     {
         CacheInit();
     }
     Dictionary<string, UserInfo> tokenList = HttpContext.Current.Cache["PASSPORT.TOKEN"] as Dictionary<string, UserInfo>;
     tokenList.Add(token, user);
 }