Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies in Sessions (Using ASP/VB)

Status
Not open for further replies.

johpje

Programmer
Jan 3, 2002
87
BE
Hi there,

I'm developing an ASP.NET app. that requires a login with userID and Password. I would like the last userID that succesfully logged in to appear in the userID.
At the moment it works, but only if i keep the same session open. If I, for example, completely close my browser and get back to the page, the UserID isn't there.

The code i use to write and read the cookies is:

' BEGIN CODE:
Public Sub setCookie(title, name, value)
Dim cookie As new Web.HttpCookie(title)
cookie.Values.Add(name, value)
Response.AppendCookie(cookie)
End Sub

Public Function getCookieValue(title, name) As String
Dim cookie As Web.HttpCookie
cookie = calPage.Request.Cookies(title)
If cookie Is Nothing Then
getCookieValue = ""
Else
getCookieValue = cookie.Values.Get(name)
End If
End Function
'END CODE


How can I permanently store and later retrieve the cookie?

Thanks a lot
Johpje
 
If you don't specify an expiration date for a cookie, the cookie is treated as an in-session cookie only. Do this to set the expiration date for one month.

Public Sub setCookie(title, name, value)
Dim cookie As new Web.HttpCookie(title)
cookie.Values.Add(name, value)
cookie.Expires = DateAdd(DateInterval.Day, 30, Today)
Response.AppendCookie(cookie)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top