HI all
I had developed a web application in Asp.net 2.0 ,In that application i have a login page to login i want to store the username in cookies, how can i make that and one more i have a dropdownlist where i can select the location , if iam selecting one location in that list it has to store in a variable, so that when i logout from that page and relogin then by default the location has to be selected,
any help greatly appreciated
Andrew FensterPosted Mar 31, 2011, 11:34 AM
HttpCookie userInfo = new HttpCookie("userInfo");
userInfo["userName"] = "someUser";
userInfo["userLocation"] = "location";
Response.Cookies.Add(userInfo);
To retrieve a cookie:
string userName = string.Empty;
string userLocation = string.Empty;
HttpCookie cookie = Request.Cookies["userInfo"];
if (cookie != null)
{
userName = cookie["userName"].ToString();
userLocation = cookie["userLocation"].ToString();
}
You should be aware that cookies are NOT safe. Someone can easily modify their own cookie to put a different user's username in it. You should not store anything sensitive or important in a cookie. You can store the user's user name in Session. You can store a user's preferences and selections in a database.
Suthish NairPosted Mar 31, 2011, 9:24 AM