WebSession.Cookies.Set

From Xojo Documentation

Method

WebSession.Cookies.Set(Name as String, Value As String [, Expiration As Date, Domain As String, Path As String, Secure As Boolean, HttpOnly As Boolean = False])

New in 2010r4

Supported for all project types and targets.

Creates a cookie for the current browser using the supplied values. Cookies are a mechanism for storing small amounts of information in a user's browser, usually for the purpose of identification.

Notes

  • Expiration: (optional) allows you to specify when the cookie expires. If Expiration is not provided, the cookie expires when the user quits their browser. When a cookie reaches its expiration date, it is removed. You can extend the expiration date of a cookie by setting the same cookie value with a date further in the future.
  • Domain: (optional) allows you to specify the domain name associated with the cookie. This is useful if your web application can be accessed from several domains, but you only want the cookie to be saved for one of them.
  • Path: (optional) allows you to specify the url path associated with the cookie.
  • Secure: (optional) tells the browser (when True) to only send the cookie to the server when it's connected through HTTPS. This setting is useful for login pages.
  • HttpOnly: (optional) prevents JavaScript from accessing the cookie.

Cookies are browser specific. If a user has multiple instances of your app open at the same time using the same browser, they will all share the same cookie information.

Sample Code

This example sets a cookie called "UserName" to the value in the userName string:

Var userName As String = "TestUser"
Session.Cookies.Set("UserName", userName)

See Also

WebSession.Cookies.Count, WebSession.Cookies.NameAtIndex, WebSession.Cookies.Remove, WebSession.Cookies.Value