expiring a persistent cookie on closing all browser windows running the website

Last post 07-02-2009 10:59 AM by masterpass. 3 replies.

Sort Posts:

  • expiring a persistent cookie on closing all browser windows running the website

    06-25-2009, 5:36 PM
    • Member
      17 point Member
    • divs_csc
    • Member since 06-22-2005, 11:47 AM
    • Posts 7

     I have the following scenario for a website:

    Custom authentication is implemented which creates an encrypted user cookie on authentication.


    I have to set this cookie to expire after a certain idle time(T) which would be set up in web.config.
    If all browser windows running my application are closed by the user before this expiry time(T),the cookie should be deleted.

    It is a web farm environment and we are not using any session management.

    I cannot use a non persistent cookie ,so basically what I need to do is expire a persistent cookie on the close of all browser windows running my web app.

    Is there any way I can achieve this?
    Some kind of javascript?

     

  • Re: expiring a persistent cookie on closing all browser windows running the website

    06-26-2009, 12:59 AM
    • Member
      196 point Member
    • masterpass
    • Member since 06-24-2009, 2:28 AM
    • Posts 48

    setTimeout(str, T);


    Use this function and form this function from the code behind and embed this to every page as startup script

    The ides is str -> will conatin script for redirecting to another page(logout.aspx) and in the other page(logout.aspx) you can write the code to destry the cookie

    T -> is the time after which you should execute the script .. take the value from the web.config .. you can get the value from by using

    System.Configuration.ConfigurationSettings.AppSettings["Inactivetime"];


    Inactivetime -> will be a key in web.config

    Thanks

    Please mark ANSWER to the post which helped you ...
  • Re: expiring a persistent cookie on closing all browser windows running the website

    06-26-2009, 3:21 PM
    • Member
      17 point Member
    • divs_csc
    • Member since 06-22-2005, 11:47 AM
    • Posts 7

     By doing this we can handle timeout for each page.

    Consider the scenario when the same website is open in two browser windows we would time out on one and have the other working.

    The desired functionality is that if the user is idle on all the open windows then it should time out,also if the user close all the windows before timeout duration,opening the websote next time should redirect to login page.

    We already have a persistent auth cookie in place which I am updating in the master page to handle idle time

    but if i close all windows and reopen it still shows logged in if the cookie has not expired. want to expire this cookie when all browser windows are closed.Dont know if that is actually possible.

     

  • Re: expiring a persistent cookie on closing all browser windows running the website

    07-02-2009, 10:59 AM
    • Member
      196 point Member
    • masterpass
    • Member since 06-24-2009, 2:28 AM
    • Posts 48

    Well, If you want the cookie to be destroyed on closing the window make it a non persistant cookie.

    that s what non-persistant cookies are for ... Let me not make a suggestion coz i don't know your scenario :)

    Thanks

    Please mark ANSWER to the post which helped you ...
Page 1 of 1 (4 items)