[ASP.NET2.0] Cookies cann't be saved if i closed the browser

Last post 10-23-2007 5:11 PM by gunteman. 1 replies.

Sort Posts:

  • [ASP.NET2.0] Cookies cann't be saved if i closed the browser

    10-23-2007, 11:05 AM
    • Member
      255 point Member
    • Professor X
    • Member since 11-15-2005, 9:54 AM
    • Posts 60

    Dear All,

    I have a problem with working with cookies, if i add cookie it works while i opening the web application and even i didn't closed the browser i works but if i close  the browser i removes everythink so how can i get it working even i closed the browser like any other website use the cookies, I use this code to make it:

     

    HttpCookie cWebApp = new HttpCookie("_cookie");
    cWebApp.Expires = DateTime.Now.AddYears(1);
    cWebApp.Values["lang"] = "en-us";

    or

     

    HttpContext httpContext = HttpContext.Current;
    httpContext.Response.Cookies["_cookie"].Values["lang"] = "value";

    am i true? i'm using firefox 2.0.0.8 and IE 7
     

     

  • Re: [ASP.NET2.0] Cookies cann't be saved if i closed the browser

    10-23-2007, 5:11 PM
    Answer
    • All-Star
      21,648 point All-Star
    • gunteman
    • Member since 07-11-2007, 8:57 AM
    • Norrköping, Sweden
    • Posts 3,177

    The first example doesn't add the cookie to the response, so it has no effect. The second example doesn't set the expiration.

     

    HttpContext httpContext = HttpContext.Current;
    httpContext.Response.Cookies["_cookie"].Values["lang"] = "value";
    httpContext.Response.Cookies["_cookie"].Expires = DateTime.Now.AddYears(1);

     

    -- "Mark As Answer" if my reply helped you --
Page 1 of 1 (2 items)