+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Write and read Cookies

Write and read Cookies

5 posts, 0 answered
  1. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    29 Sep 2010
    Link to this post
    Hello Telerik Team,
    I have a big problem with "third-party cookies"!
    I Have IE7 and I use Javascript to Write and Read Cookies!
    every thing is well.
    when I close my browser and open a new one I loose all My cookies,
    My IE7 doest save my "third-party cookies"
    In my global.asax I set My header like this:
    protected void Application_BeginRequest(object sender, EventArgs e)
       {
           HttpContext.Current.Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
         }
    But Nothing!
    I have set my  security level in my Internet Options ->Advanced menu to Medium!
    Any Idea!
    thank you very much!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Sep 2010
    Link to this post
    Hello Bachar Zeidan,

    Does the cookies get clear only in IE 7? What about the other browsers? It is possible that when the browser is closed it is clearing all private data. There is a browser option "Delete browsing history on exit" which might be turned on.

    Also you can use HttpModule or Handler and Response.Cookies["key"].Value = "some value" to set your cookie.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    30 Sep 2010
    Link to this post
    Hello Again,
    I have the same problem with other Browser FF and Safari.
    The browser option "Delete browsing history on exit" is not flagged.
    I'm sending Cookies to my browser With a Javascript Function!
    There is a different between Sending Cookies to browser with javascript function  and sending cookies with  Response.Cookies["key"].Value ?
    I tried to set this code in my MasterPageBase in the Onload Event :
    HttpContext.Current.Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""); 

    With no result!



  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Oct 2010
    Link to this post
    Hi Bachar,

    Persistent cookies are stored at the users end, separately for every browser user and separately for every browser. Internet Explorer stores every cookie in a separate files

    I prepared a basic sample where I am setting the cookie through js code and it does not get deleter after I close the browser and then open it again. My cookie gets cleared only when I clear the browser cookies manually.

    <script type="text/javascript">
     
        function addCookie(cookieName, value, days) {
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
                var expires = "; expires=" + date.toGMTString();
            }
            else var expires = "";
            document.cookie = cookieName + "=" + value + expires + "; path=/";
        }
     
        function checkCookie(cookieName) {
            var name = cookieName + "=";
            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(name) == 0) return c.substring(name.length, c.length);
            }
            return null;
        }
     
        function deleteCookie(name) {
            addCookie(name, "", -1);
        }
     
    </script>
     
    <a href="javascript:addCookie('PersistentCookie', 'test', '2')">Add a cookie </a><br>
    <a href="javascript:checkCookie('PersistentCookie')" >Read a cookie</a><br>
    <a href="javascript:deleteCookie('PersistentCookie')" >Delete a cookie</a>.

    Form what you are saying it looks like your cookie does not go to Cookie header of http respopnse and probably you are not persisting the cookies. The persistence depends on the expiration value which is set for a given cookie and this is why when I call deleteCookie, I set this value to -1. 

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    01 Oct 2010
    Link to this post
    Hello Ivan Dimitrov ,
    First of all I want to thank you for your support!
    Finally I resolved the problem!
    I had the expiration Value equal Zero (0).
    it was really my stupid inattention!
    thank you again!
Register for webinar
5 posts, 0 answered