Cookie and Session Cookie Questions.

S

Shapper

Hello,

I am working on an ASP.NET / VB web page.

How can I set a cookie in my visitor computer and also a Session Cookie?
And how can I retrieve their values?

I will run it when page loads.

Thank You,
Miguel
 
M

Mona

Hi Miguel,

You can use the Response object of ASP.NET to write cookies.
The Response object has a Cookies collection to which you add the
cookies you want to write to the browser.

You can add cookies to the Response.Cookies collection in a couple of ways.
The following example shows two methods to accomplish the task:
Response.Cookies("userName").Value = "mike"
Response.Cookies("userName").Expires = DateTime.Now.AddDays(1)

Dim aCookie As New HttpCookie("lastVisit")
aCookie.Value = DateTime.Now.ToString
aCookie.Expires = DateTime.Now.AddDays(1)
Response.Cookies.Add(aCookie)Following is a link which discusses this topic in detail:

[Basics of Cookies in ASP.NET]
http://msdn.microsoft.com/library/d...s/dv_vstechart/html/vbtchASPNETCookies101.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top