Best Way to Display Cookie Value?

Posted by Community Admin on 04-Aug-2018 21:19

Best Way to Display Cookie Value?

All Replies

Posted by Community Admin on 21-Nov-2011 00:00

When a visitor hits my site for the first time a cookie is set based on the referral source (Google, Yahoo, etc.) and based on the source a unique toll free phone number is set to a cookie.  What is the best way to display that cookie phone number value?  It will be displayed in mulitple places on the web site include content paragraphs, custom controls, etc.

Posted by Community Admin on 24-Nov-2011 00:00

Hi Matt,

How do you want to display the cookie - via client code or via server code? Here is a method for reading a cookie with a specific name:

function readCookie(name)
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    
    return null;

While with server code you can read cookies using Request.Cookies, which will return a CookieCollection that you can parse.

Kind regards,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 25-Nov-2011 00:00

Thanks for the response.  This will save me a bunch of time.

This thread is closed