473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Set Cookie code - cookie erases when browser session is closed

I wrote this code,

seems to work fine when the browser is open, but once the session ends or the browser closes, the cookie deletes itself.

I''m sure it's something really simple but I don't know what it is.

Any help would be greatly appreciated
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. For the Remember me field
  4.  
  5.  
  6.  
  7.  
  8. If Cookie = True Then
  9.  
  10.  
  11.  
  12.                             Dim MembersCookie As New HttpCookie(CookieSiteName)
  13.  
  14.                             'Context.Response.Cookies.Remove(CookieSiteName)
  15.  
  16.                             'MembersCookie.Values.Add("Login", Username)
  17.                 'encrypts cookie data
  18.                             SecureCookie.SetCookie(Context.Response, "Login", Username)
  19.  
  20.                 'encrypts cookie data
  21.                             'MembersCookie.Values.Add("Pass", Password)
  22.                             SecureCookie.SetCookie(Context.Response, "Pass", Password)
  23.  
  24.                             MembersCookie.Values.Add("AutoLogin", "On")
  25.                             ' MembersCookie.Domain = "www.ReefJunkies.Org"
  26.                             Dim dtExpiry = DateTime.Now.AddDays(15) 'you can add years and months too here
  27.  
  28.                             Context.Response.Cookies(CookieSiteName).Expires = dtExpiry
  29.                             Context.Response.Cookies.Add(MembersCookie)
  30.  
  31.                         ElseIf Cookie = False Then
  32.  
  33.                             'Change autologin in cookie to off
  34.                             Dim cookie As HttpCookie = Context.Request.Cookies.Get("ReefJunkies")
  35.  
  36.                             cookie.Values.Add("AutoLogin", "Off")
  37.  
  38.                             Context.Response.Cookies.Add(cookie)
  39.  
  40.                             'Context.Response.Cookies.Remove(CookieSiteName)
  41.  
  42.                         End If
  43.  
  44.  
  45.  
  46. For the logout
  47.  
  48.  
  49.  
  50.         'Change autologin in cookie to off
  51.         Dim cookie As HttpCookie = Request.Cookies.Get("ReefJunkies")
  52.  
  53.         cookie.Values.Add("AutoLogin", "Off")
  54.  
  55.         Response.Cookies.Add(cookie)
  56.  
  57.         Response.Redirect(Application("LogOutPage"))
  58.  
  59.  
Jan 10 '11 #1
0 1269

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jennifer Smith | last post by:
We have an environment running ASP on IIS5, where a user logs in via an ASP login page and an entry is made to the database recording the users login time and a database session. If the user then...
4
by: Nikhil Patel | last post by:
Hi all, I am writing an ASP.Net app. I first read application data from Sql Server and store it in a DataSet. When the user is no longer running the application, I would like to save the contents...
4
by: Rob R. Ainscough | last post by:
Response.Redirect seems to only work with current window session -- how can I use ASP.NET (VB.NET) code to launch my URL in a new browser window? Thanks, Rob.
6
by: toffee | last post by:
Hi all, i have several php files which each run a different SELECT query and displays the data in a table. I would like to create an option to export the table to excel and one route i would...
3
by: Amar | last post by:
Hi all, I want to use a cookie that will destroy after closing the browser, in my application. I am able to destroy my cookie after log out,but don't know how to destroy this when I will ...
4
AnuSumesh
by: AnuSumesh | last post by:
Hi I want that if user is logged in on one machine and trying to log in another machine also then he should not be allowed to log in again. For that-- i am creating Dictionary object on...
13
by: Gouri.Mahajan7 | last post by:
Hello, Can anybody please tell me how to trap the browser close event. when that is fired I want to call the web method. Thanks in advance. Regards, Gouri.
12
by: jodleren | last post by:
Hi I did not notice. A system I have made, seems on one server to keep the $_SESSION even when the browser has been closed... How can I avoid that? WBR Sonnich
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.