protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)//On first time
if (Request.Cookies["myCookie"] != null) //Cookie Exists??
HttpCookie cookie = Request.Cookies.Get(myCookie");
string user = cookie.Values["user"].ToString();
if (user != "")
Logeo.UserName = user; //Write the username onto login username textbox
Already the read cookie process, now we have to implement the other task, write the user name to the cookie.
Figure 5. Remember check the box.
When you press the login button a logged in process is fired up, we must to write the create process synthax for the cookie at this time, check the next code lines.
protected void Logeo_LoggedIn(object sender, EventArgs e)
CheckBox chBox = (CheckBox)Logeo.FindControl("RememberMe");
HttpCookie myCookie = new HttpCookie("myCookie"); //Instance the new cookie
Response.Cookies.Remove("myCookie"); //Remove previous cookie
Response.Cookies.Add(myCookie); //Create the new cookie
myCookie.Values.Add("user", this.Logeo.UserName); //Add the username field to the cookie
DateTime deathDate = DateTime.Now.AddDays(15); //Days of life
Response.Cookies["myCookie"].Expires = deathDate; //Assign the life period
//IF YOU WANT SAVE THE PASSWORD TOO (IT IS NOT RECOMMENDED)
That was the implementation for remember me next time feature using cookies to save onto the user pc, be carefully with all the information that you save there. Because an experienced user could read it.
There are more and complicated ways to login registered users, so this is one of the most basics and easy to implement login tasks, enjoy it.
This task look hard but you can do it as easy as you want, feel Free to make any changes.