PDA

View Full Version : Storing more information using FormsAuthentication



saeed31641
پنج شنبه 03 اردیبهشت 1394, 11:17 صبح
سلام من از سیستم اعتبار سنجیAuthentication استفاده می کنم .میخام یسری اطلاعات اضافی مثل نام و فامیل رو کش کنم که اینکار با userdata انجام میشه حال چطور استخراج کنم .

public void SignIn(P_UserLogon_List_Result user, bool createPersistentCookie)
{
if (user == null)
throw new ArgumentNullException("user");
if (user.UserName == "administrator")
{
user.Role_name = "administrator";
var cookie = new LabCookie
{
UserName = user.UserName,
FirstName = user.Name,
LastName = user.Family,
RememberMe = false,
// Roles = new List<string> { "administrator" }
Roles = new List<string> { user.Role_name ?? "user" }
};
string userData = JsonConvert.SerializeObject(cookie);
var ticket = new FormsAuthenticationTicket(1, cookie.UserName, DateTime.Now,
DateTime.Now.Add(FormsAuthentication.Timeout),
createPersistentCookie, userData);
string encTicket = FormsAuthentication.Encrypt(ticket);
var httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket) { Expires = DateTime.Now.Add(FormsAuthentication.Timeout) };

_httpContext.Response.Cookies.Add(httpCookie);


}




من میخام الان family , name بگیرم و نشون بدم