国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新乐市| 郴州市| 枝江市| 阳新县| 桃园县| 芦山县| 盐源县| 宁海县| 弥勒县| 浏阳市| 蒙自县| 苗栗市| 光山县| 丘北县| 佛山市| 南郑县| 调兵山市| 吉林省| 元氏县| 泽库县| 金阳县| 青阳县| 孙吴县| 商南县| 靖安县| 石台县| 黎川县| 桂平市| 天峻县| 瓦房店市| 五莲县| 阳信县| 宜章县| 邵东县| 常宁市| 封开县| 崇信县| 凭祥市| 扎囊县| 广饶县| 旺苍县|