Cookies problem in ASP.net
I am currently working on an ASP.net c# web application. I am trying to use a cookie which will store the users id number from the database.
I set the cookie when the user logs in using the following code:
Response.Cookies["userID"].Value = reader.GetString("use_id");
When the user logs in it does a Response.Redirect to /software/index.aspx.
This file then retrieves the value of the cookie with the following code
HttpContext.Current.Request.Cookies["userID"].Value
When开发者_如何学C I then click a link to a different page e.g. ../accounts/index.aspx and I try to run the same code to get the value of the cookie, the value is empty.
What am I doing wrong.
Thanks for any help you can provide.
Try using the Add method on the cookies collection and see if it makes a difference:
Response.Cookies.Add(new HttpCookie("userID")
{
Expires = DateTime.Now.AddDays(1),
Value = reader.GetString("use_id"),
HttpOnly = true
});
Edit: Typos.
Have you set an expiry time on the cookie?
Is the index.aspx a page on the same site that gave you the cookie?
精彩评论