Cookies in X++

Cookies are often used in web applications to maintain some data on the browser machine and sent back to the server everytime across multiple page visits from the same site/domain untill it expires.

The user can set the browser option to accept cookies or not. So before using cookies,  these considerations along with other security and privacy considerations should be carefully thoughout.

EP framework provides way to read and write cookies from X++ code  executed by EP. Below is a sample code snippet to read and write cookie in X++ 

IISRequest r;
;

//Write Cookie with a set expiration date 
webSession().response().cookies().itemWriteCookie("CustomerName=mey; expires=Fri, 31-Dec-2010 23:59:59 GMT");

//Read cookie from the Request object
r = new IISRequest();
webSession().writeTxt(r.cookies().itemTxt(("customerName")));