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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

網(wǎng)站用戶登錄認證

2019-11-14 14:35:01
字體:
供稿:網(wǎng)友

cookie登錄后同域名下的網(wǎng)站保持相同的登錄狀態(tài)。

登錄

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)//是否在設(shè)置的過期時間內(nèi)一直有效  {    cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted)    {      HttpOnly = true,      Path = FormsAuthentication.FormsCookiePath,      Secure = FormsAuthentication.RequireSSL,      Expires = ticket.Expiration,      Domain = "VEVb.com"http://這里設(shè)置認證的域名,同域名下包括子域名如aa.VEVb.com或bb.VEVb.com都保持相同的登錄狀態(tài)    };  }  else  {    cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketEncrypted)    {      HttpOnly = true,      Path = FormsAuthentication.FormsCookiePath,      Secure = FormsAuthentication.RequireSSL,      //Expires = ticket.Expiration,//無過期時間的,瀏覽器關(guān)閉后失效      Domain = "VEVb.com"    };  }  HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);  HttpContext.Current.Response.Cookies.Add(cookie);
}

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

判斷用戶是否登錄

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

得到當(dāng)前的用戶名

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

 


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 五莲县| 浦北县| 玛纳斯县| 景东| 河间市| 梁平县| 阿鲁科尔沁旗| 将乐县| 双柏县| 上犹县| 西贡区| 萝北县| 洪雅县| 商南县| 普定县| 丘北县| 中超| 华亭县| 竹山县| 宿州市| 吐鲁番市| 安化县| 浮山县| 米林县| 明溪县| 邹平县| 丰台区| 六安市| 龙岩市| 兴国县| 洞口县| 台南县| 呼伦贝尔市| 西乡县| 临泽县| 辽宁省| 溆浦县| 酉阳| 宣城市| 修文县| 富川|