i'm just starting my ventures into .NET
i'm trying to create a hash table to store in a cookie and then read it back as a string, convert it back to a hashtable and life is all good.
i dont know how to read it back though. Below is the 2 chunks of code i'm using to attempt this. The second chunch (the part that reads it) is the part that isn't working. I dont really expect it to in its current form, but in included it so you could see what I am trying to accomplish. Thanks
//create cookie with data
//-----------------------------------------------
string roles = GetRoles(myDataReader["username"].ToString());
Hashtable testHash = new Hashtable();
testHash.Add("roles", roles);
testHash.Add("uid", myDataReader["userID"]);
string stringedHash = testHash.ToString();
//store those roles in an encrypted ticked and then throw that ticket into the cookie
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, myDataReader["username"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, stringedHash);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);
//read cookie and convert back to hashtable
//----------------------------------------------------
string cookieData = authTicket.UserData.ToString();//Split(new char[]{','});
Hashtable testHash = (Hashtable)cookieData;
string roles = testHash["roles"].ToString();
string userID = testHash["uid"].ToString();
i'm trying to create a hash table to store in a cookie and then read it back as a string, convert it back to a hashtable and life is all good.
i dont know how to read it back though. Below is the 2 chunks of code i'm using to attempt this. The second chunch (the part that reads it) is the part that isn't working. I dont really expect it to in its current form, but in included it so you could see what I am trying to accomplish. Thanks
//create cookie with data
//-----------------------------------------------
string roles = GetRoles(myDataReader["username"].ToString());
Hashtable testHash = new Hashtable();
testHash.Add("roles", roles);
testHash.Add("uid", myDataReader["userID"]);
string stringedHash = testHash.ToString();
//store those roles in an encrypted ticked and then throw that ticket into the cookie
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, myDataReader["username"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, stringedHash);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(authCookie);
//read cookie and convert back to hashtable
//----------------------------------------------------
string cookieData = authTicket.UserData.ToString();//Split(new char[]{','});
Hashtable testHash = (Hashtable)cookieData;
string roles = testHash["roles"].ToString();
string userID = testHash["uid"].ToString();