More in this section

Forums / Developing with Sitefinity / Best Way to Display Cookie Value?

Best Way to Display Cookie Value?

3 posts, 0 answered
  1. Matt
    Matt avatar
    35 posts
    Registered:
    01 Nov 2010
    21 Nov 2011
    Link to this post
    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.

  2. Lubomir Velkov
    Lubomir Velkov avatar
    688 posts
    Registered:
    03 Nov 2014
    24 Nov 2011
    Link to this post
    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
  3. Matt
    Matt avatar
    35 posts
    Registered:
    01 Nov 2010
    25 Nov 2011
    Link to this post
    Thanks for the response.  This will save me a bunch of time.
3 posts, 0 answered