protected void Page_Load(object sender, EventArgs e)<o:p>
{<o:p>
if (!IsPostBack)//On first time
{<o:p>
if (Request.Cookies["myCookie"] != null) //Cookie Exists??
{<o:p>
HttpCookie cookie = Request.Cookies.Get(myCookie");<o:p>
string user = cookie.Values["user"].ToString();<o:p>
if (user != "")<o:p>
{<o:p>
Logeo.UserName = user; //Write the username onto login username textbox
}<o:p>
}<o:p>
}<o:p>
}
<o:p>
Already the read cookie process, now we have to implement the other task, write the user name to the cookie.
<o:p>
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)<o:p>
{<o:p>
CheckBox chBox = (CheckBox)Logeo.FindControl("RememberMe");<o:p>
if (chBox.Checked)<o:p>
{<o:p>
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<o:p>
Response.Cookies["myCookie"].Expires = deathDate; //Assign the life period
//IF YOU WANT SAVE THE PASSWORD TOO (IT IS NOT RECOMMENDED)
myCookie.Values.Add("pass", this.Logeo.Password);<o:p>
}
}<o:p>
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.
Conclusion
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.