---
title: "How to create remember me checkbox to remember session until user Logout explicitly"  
description: "How to create remember me checkbox to remember session until user Logout explicitly"  
author: "Anonymous User"  
published: 2014-08-26  
updated: 2023-07-06  
canonical: https://www.mindstick.com/forum/2143/how-to-create-remember-me-checkbox-to-remember-session-until-user-logout-explicitly  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# How to create remember me checkbox to remember session until user Logout explicitly

If [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) directly [close](https://yourviews.mindstick.com/story/1687/rubbing-hands-close-up-benefits) their [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser) without clicking logout then next time they open browser its [session](https://www.mindstick.com/articles/12042/session-in-c-sharp) will be maintained as it is till they logout explicitly by clicking Logout [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net)

I want to do it in [vb.net](https://www.mindstick.com/forum/426/sqlsever-2000-in-network-with-vb-dot-net-2008) !

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that. Here are the steps on how to create a remember me check box to remember session until user logout explicitly:

1. Create a new ASP.NET Web Forms project.
2. Add a CheckBox control to the form.
3. In the code behind file, add the following code:

VB.Net

```plaintext
Protected Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
    ' If the checkbox is checked, set the remember me cookie.
    If CheckBox1.Checked Then
        Dim cookie As HttpCookie = New HttpCookie("RememberMe")
        cookie.Value = "1"
        cookie.Expires = DateTime.Now.AddDays(30)
        Response.Cookies.Add(cookie)
    Else
        ' If the checkbox is unchecked, delete the remember me cookie.
        Dim cookie As HttpCookie = Response.Cookies("RememberMe")
        Response.Cookies.Remove(cookie)
    End If
End Sub
```

1. Run the project. When you check the checkbox, a cookie will be set that will remember the user's session for 30 days. When the user logs out, the cookie will be deleted.

Here is an explanation of the code:

- The `CheckedChanged` event is raised when the Checked property of the CheckBox control changes.
- The `HttpCookie` class represents a cookie.
- The `Value` property of the `HttpCookie` class sets the value of the cookie.
- The `Expires` property of the `HttpCookie` class sets the expiration date of the cookie.
- The `Cookies` property of the `Response` object gets the collection of cookies for the current request.
- The `Add` method of the `Cookies` property adds a cookie to the collection.
- The `Remove` method of the `Cookies` property removes a cookie from the collection.

### Reply by Sumit Kesarwani

Hi John, \

Simply pass true as second parameter when emitting the authentication cookie:

FormsAuthentication.RedirectFromLoginPage(Username, true)

This will create a persistent authentication cookie on the client whose expiration is handled by the timeout property in your web.config:

```
<forms   loginUrl="~/login.aspx"   defaultUrl="~/default.aspx"   protection="All"   timeout="3600"</forms>
```


---

Original Source: https://www.mindstick.com/forum/2143/how-to-create-remember-me-checkbox-to-remember-session-until-user-logout-explicitly

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
