session and cookies

Discussion in 'ASP.NET 2.0' started by vagelis, Aug 26, 2010.

  1. i use this code for implement the remember me
    (to icrease the duration that a client is authenticated)

    Code:
    FormsAuthentication.Initialize()
                Dim expires As DateTime = DateTime.Now.AddDays(20)
                Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, tbox_username.Text, DateTime.Now, expires, True, String.Empty, FormsAuthentication.FormsCookiePath)
                Dim encryptedTicket As String = FormsAuthentication.Encrypt(ticket)
                Dim authCookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
                authCookie.Expires = expires
                Response.Cookies.Add(authCookie)
    
    but although it works in my visual studio it doesnt work in the server

    any idea why??
     
  2. By "doesn't work in the server", what exactly do you mean? Is it just not working at all, or getting logged out after a bit?
     
  3. sory you are right i must be more accurate

    the problem is that is as it doesnt exist this code

    in my localhost by visual studio with this code the coockies duration is 20 days

    in the discountasp.net host the coockie expires very soon

    i think about 20-30 minutes
     
  4. but this is for the coockies not for the sessions
    i think that the coockies go to the clients pc and the sessions have to do with the server

    or they have some similarities in the way that they are handled from the server??
     
  5. mjp

    mjp

    Well, like you said, the cookie is in the user's browser, so when it expires is unrelated to anything happening on the server.

    Are you sure you aren't sending the cookie more than once? It's possible that you try to send the cookie a second time and it is overwriting the first instance, which could, theoretically, kill anything under the first cookie...just a thought.

    Otherwise the cookie expiration is happening due to something client-side.
     
  6. yes i am surte because it works in my localhost from my visual studio
    the problem is in the online page that is hosted on discountasp.net
     
  7. Sessions dont get lost on your local machine. So the comparisons are not going to help you resolve your issue.

    If the application is recycled (on our servers), the session is terminated, the user is no longer authenticated, the token is no longer valid and the process starts again. Address your session issue and your cookie issue should no longer be a problem.
     

Share This Page