日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ASP.NET的票据工具类FormsAuthenticationTicket

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

?

?

public class TicketTool{/// <summary>/// 創建一個票據,放在cookie中/// 票據中的數據經過加密,解決了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>/// 取得票據中數據/// </summary>/// <returns></returns>public static string GetUserData(){return (HttpContext.Current.User.Identity as FormsIdentity).Ticket.UserData;}}

?

轉載于:https://www.cnblogs.com/sharing1986687846/p/10311462.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。