public string GetFromCookieData() { string sCookieName = FormsAuthentication.FormsCookieName; HttpCookie authCookie = HttpContext.Current.Request.Cookies[sCookieName]; if (authCookie == null) { //跳转到登录页 try { System.Web.UI.Page page = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler; if (page != null) { page.Response.Write("<script> top.location.href='" + Helper.GetAppSettings("HomePageUrl") + "';</script>"); } return(null); } catch (Exception e) { return(null); } } FormsAuthenticationTicket authTicket = null; authTicket = FormsAuthentication.Decrypt(authCookie.Value); if (authTicket == null) { HttpContext.Current.Response.Clear(); FormsAuthentication.RedirectToLoginPage(); HttpContext.Current.Response.End(); return(null); } if (!authTicket.Expired && FormsAuthentication.SlidingExpiration) { FormsAuthenticationTicket newTicket = FormsAuthentication.RenewTicketIfOld(authTicket); if (authTicket.Expiration != newTicket.Expiration) { string encTicket = FormsAuthentication.Encrypt(newTicket); authCookie.Value = encTicket; authCookie.Expires = newTicket.Expiration; authCookie.Domain = FormsAuthentication.CookieDomain; HttpContext.Current.Response.Cookies.Remove(sCookieName); HttpContext.Current.Response.Cookies.Add(authCookie); } } string sData = authTicket.UserData; sData = OEncryp.Decrypt(sData); return(sData); }
/// <summary> /// 设置页面信息 /// </summary> /// <param name="id">ID</param> private void SetPage(string id) { DataTable dt = bll.GetPagingSigInfo("0", "0", " where userid=" + id); if (dt != null && dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; txt_uname.Text = dr["uname"].ToString(); txt_pwd.Text = OEncryp.Decrypt(dr["upwd"].ToString()); txt_pwd.Enabled = false; txt_role.Text = dr["rolename"].ToString(); hidroleid.Value = dr["roleid"].ToString(); ddl_status.SelectedValue = dr["status"].ToString(); txt_descr.Text = dr["remark"].ToString(); } }