Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Accessing part of a cookie View modes: 
User avatar
Member
Member
Oli Jeffery - 2/3/2011 8:15:19 AM
   
Accessing part of a cookie
Hi,

I have a cookie that I’m accessing through a cookie macro in Kentico using
{@UserSettings@}
.

It has three properties, so is currently displaying as

Large=false&Business=true&Individual=false

How would I get it to display only part of the cookie, e.g. the value of Business?

Thanks, Oli Jeffery.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 2/3/2011 2:54:24 PM
   
RE:Accessing part of a cookie
Hello.

In current version, you can use custom macro for this purpose only. You can see example of use here: devnet.kentico.com/docs/devguide/appendix_a___macro_expressions.htm

In code, you can get given cookie via:

HttpCookie GetExistingCookie(
string cookieName
)


method in CMS.GlobalHelper.CookieHelper class.

It returns HttpCookie object with Value property. Using this property, you can parse it according to your needs.

Best Regards,
Radek Macalik

User avatar
Member
Member
Oli Jeffery - 2/8/2011 3:22:28 AM
   
RE:Accessing part of a cookie
Hi,

Thanks for your help on and off the forums... in case anyone wants to do the same sort of thing as me, here's the custom macro I eventually used:
case "v_lar":

match = true;
if (HttpContext.Current.Request.Cookies["UserSettings"] != null)
{result = HttpContext.Current.Request.Cookies["UserSettings"]["Large"].ToString();}
else {result = "false";}

break;


The cookie value is set as either true or false, making it suitable for a visibility property, and if no cookie is set, it also defaults to false.