日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET的票据工具类FormsAuthenticationTicket

發(fā)布時間:2025/7/14 asp.net 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET的票据工具类FormsAuthenticationTicket 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

?

public class TicketTool{/// <summary>/// 創(chuàng)建一個票據(jù),放在cookie中/// 票據(jù)中的數(shù)據(jù)經(jīng)過加密,解決了cookie的安全問題。/// </summary>/// <param name="username"></param>public static void SetCookie(string username, string userData){FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(60), false, userData, FormsAuthentication.FormsCookiePath);string encTicket = FormsAuthentication.Encrypt(ticket);HttpCookie newCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);HttpContext.Current.Response.Cookies.Add(newCookie);}/// <summary>/// 通過此法判斷登錄/// </summary>/// <returns>已登錄返回true</returns>public static bool IsLogin(){return HttpContext.Current.User.Identity.IsAuthenticated;}/// <summary>/// 退出登錄/// </summary>public static void Logout(){FormsAuthentication.SignOut();}/// <summary>/// 取得登錄用戶名/// </summary>/// <returns></returns>public static string GetUserName(){return HttpContext.Current.User.Identity.Name;}/// <summary>/// 取得票據(jù)中數(shù)據(jù)/// </summary>/// <returns></returns>public static string GetUserData(){return (HttpContext.Current.User.Identity as FormsIdentity).Ticket.UserData;}}

?

轉(zhuǎn)載于:https://www.cnblogs.com/sharing1986687846/p/10311462.html

總結(jié)

以上是生活随笔為你收集整理的ASP.NET的票据工具类FormsAuthenticationTicket的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。