how can we identify the user by using cookies ?

Posted by Rajeshk under ASP.NET on 4/12/2013 | Points: 10 | Views : 895 | Status : [Member] | Replies : 1
hi all,

how can we identify the user by using cookies if the user logs 2nd time with previous credentials,because we destroying the the
cookies by signout() method plz resolve my answer with cookies only,thank you



Posted by: Singarapu_Kranthi on: 4/12/2013 [Member] Starter | Points: 25


You can create a cookie (that will expire when the browser closed) to identify the first visit, and a never expire cookie to identify the visited user.

sample demo

// You need to call this code from all pages
protected void Page_Load(object sender, EventArgs e)
if (Request.Cookies["visited"] == null && Request.Cookies["firstVisit"] == null)
// Will expire when the browser closed
HttpCookie firstVisit = new HttpCookie("firstVisit", "true");

// Never expire cookie flag
HttpCookie visited = new HttpCookie("visited", "true");
visited.Expires = DateTime.Now.AddYears(100);

// Detect status
if (Request.Cookies["firstVisit"] != null)
Response.Write("You are now in the first visit.<br />");
Response.Write("You have visited this site last time.<br />");

Rajeshk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response