locked
cookies lost when webpage closed. RRS feed

  • Question

  • User854792261 posted

    i m saving cookies in a page with 

                Response.Cookies("BRANCHNAME").Value = myreader("B_NAME")
    
    
    and i can check before leaving page that cookie is stored. but when i move to next page. cookie become blank. i m 
    using framework 4.
    Saturday, August 27, 2011 9:52 AM

Answers

  • User-731944376 posted
    Use below statement for getting the cookie value.
    Request.Cookies("BRANCHNAME").Value

    I guess, we should set the expiry date.Not sure


    For Interview Questions and Answers:
    www.knowfreely.com

    Thanks,
    Ajay
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 28, 2011 1:05 PM

All replies

  • User-731944376 posted
    Use below statement for getting the cookie value.
    Request.Cookies("BRANCHNAME").Value

    I guess, we should set the expiry date.Not sure


    For Interview Questions and Answers:
    www.knowfreely.com

    Thanks,
    Ajay
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 28, 2011 1:05 PM
  • User960609757 posted

    Hi,

    If you set an expiration date, this will set them to expire on that date, whether the browser is open or closed.

    Only non persisted cookies will expire once the browser is closed.

    Response.Cookies["test"].Value = "cookie test";
    Response.Cookies["test"].Expires = DateTime.MaxValue;

    The Expires property of a cookie defaults to DateTime.MinValue (00:00:00.0000000, January 1, 0001).  So adding 1 month to that still results in an expired cookie.

    If you want to set it to expire 1 month from today, then you can do it like this:

    Response.Cookies["test"].Expires = DateTime.Now.AddMonths(1);

    
    
    Monday, August 29, 2011 3:00 AM