国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

網站用戶登錄認證

2019-11-14 14:26:10
字體:
來源:轉載
供稿:網友

cookie登錄后同域名下的網站保持相同的登錄狀態。

登錄

PRivate void SetAuthCookie(string userId, bool createPersistentCookie)
{
  var
ticket = new FormsAuthenticationTicket(2, userId, DateTime.Now, DateTime.Now.AddDays(7), true, "", FormsAuthentication.FormsCookiePath);  string ticketEncrypted = FormsAuthentication.Encrypt(ticket);  HttpCookie cookie;  if (createPersistentCookie)//是否在設置的過期時間內一直有效  {    cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted)    {      HttpOnly = true,      Path = FormsAuthentication.FormsCookiePath,      Secure = FormsAuthentication.RequireSSL,      Expires = ticket.Expiration,      Domain = "VEVb.com"http://這里設置認證的域名,同域名下包括子域名如aa.VEVb.com或bb.VEVb.com都保持相同的登錄狀態    };  }  else  {    cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted)    {      HttpOnly = true,      Path = FormsAuthentication.FormsCookiePath,      Secure = FormsAuthentication.RequireSSL,      //Expires = ticket.Expiration,//無過期時間的,瀏覽器關閉后失效      Domain = "VEVb.com"    };  }  HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);  HttpContext.Current.Response.Cookies.Add(cookie);
}

這樣登錄后,在同域名下的任何頁面都可以得到用戶狀態

判斷用戶是否登錄

public bool IsAuthenticated{  get  {    bool isPass = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;    if (!isPass)      SignOut();    return isPass;  }}

得到當前的用戶名

public string GetCurrentUserId(){     return _httpContext.User.Identity.Name;}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高要市| 吉木乃县| 大连市| 镶黄旗| 富平县| 普陀区| 泗阳县| 河曲县| 昭苏县| 巴彦县| 宝兴县| 苏尼特右旗| 尉犁县| 洛阳市| 和田县| 武安市| 洪泽县| 哈尔滨市| 库伦旗| 东丰县| 南木林县| 都匀市| 南华县| 汤阴县| 基隆市| 柳河县| 天峻县| 长岛县| 乡城县| 溆浦县| 灵台县| 丰镇市| 霍城县| 合水县| 洪江市| 清丰县| 朝阳县| 宾川县| 临沧市| 任丘市| 横峰县|