How do HTTP-based Components Handle Cookies?

The Cookies property, the AddCookie method, and the SetCookie event can all be used to interact with cookies.

Date Entered: 12/14/2000    Last Updated: 03/08/2017

The Cookies property

.NET and Java Editions

In .NET and Java editions, the Cookies property is a collection of HTTPCookie objects for each cookie that has been set in the current HTTP session. These objects store the required Name and Value of the cookie as well as the optional Domain, Expiration, Path, and Secure flag. The Cookies collection can be modified directly to add or remove cookies.

All Other Editions (C++, Delphi, etc)

In editions other than .NET and Java, there is no single Cookies property; rather the cookies are represented in a series of array properties such as CookieName and CookieValue. The CookieCount property governs the size of these arrays, and the arrays are 'aligned' such that CookieName[0] and CookieValue[0] refer to the same cookie.

AddCookie

The AddCookie method can also be used to easily define a new Name-Value pair to the Cookies collection. The behavior of this method is identical across all editions. In editions other than .NET and Java, it is recommended to use this method to add cookies rather than altering the Cookie* array properties directly. This is to ensure that CookieCount and the Cookie* arrays do not get misaligned.

SetCookie

When a cookie is set by the server, the SetCookie event will fire. The cookie values are exposed inside the event as event parameters. The Cookies collection (or Cookie* array properties in editions other than .NET and Java) is also automatically updated with the new cookies set by the server. The behavior of this event is identical across all editions.


We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at kb@nsoftware.com.