locked
Clearing session when redirecting to another page RRS feed

  • Question

  • User858479128 posted

    Hi all,

    I'm working on web application and we use session to store many data in each page. If the user visits pages then leave it and visit another one

    and leave it and so on, Sessions are created but not cleared, so I need a mechanism where I can check if the user is redirecting to another page and clears the session the current page uses 

    Sunday, April 3, 2011 6:26 AM

Answers

  • User858479128 posted

    Thanks all for your replies the problem with me was the redirection that is not from the page itself was the redirection from the left menu of the site.

    and I found a solution and it is as follows :

    using onunload javascript method to post back to the server with an argument that tell the page to clear the session variables used in it

    it was a good solution for me

    Thanks all again

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 5, 2011 4:21 AM

All replies

  • User-1923420989 posted

    use session.abandon() method while you re-direct, it will destroy all the session objects

    Sunday, April 3, 2011 8:27 AM
  • User-481631678 posted

    If you want to store information which is required on current page only and it is not required for other pages, then instead of storeing that in session, you better store them in viewstate or hidden field. For details see recommendations for state management:-


    http://msdn.microsoft.com/en-us/library/z1hkazw7%28VS.80%29.aspx

    Monday, April 4, 2011 12:26 AM
  • User858479128 posted

    I cannot use session.Abandon because there are a session used to store current logged in user and location and so on ... also I don't understand what you mean by while redirecting "Which event do you want me to use? "

    Thanks for your reply

    Monday, April 4, 2011 8:22 AM
  • User858479128 posted

    I cannot use viewstate because many data are used while using the page so the page size will be bigger and will cause performance issues

     

    Monday, April 4, 2011 8:23 AM
  • User-638545559 posted

    Hi, While you come to new page on pag eload of new page you can clear session like this : Session["SessionVar"] = null;

     

    Monday, April 4, 2011 9:17 AM
  • User-519136805 posted

    Hi ghost1484,

    you want to clear all the session variable or just created for the page from where you are looking to redirect?

    if that is the case than before you redirect to another page just clear the session variables that you have created for current page and than redirect to that page.

    Hope this will help !!!

     

    Monday, April 4, 2011 10:09 AM
  • User858479128 posted

    Thanks all for your replies the problem with me was the redirection that is not from the page itself was the redirection from the left menu of the site.

    and I found a solution and it is as follows :

    using onunload javascript method to post back to the server with an argument that tell the page to clear the session variables used in it

    it was a good solution for me

    Thanks all again

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 5, 2011 4:21 AM
  • User-1561814533 posted

    Whilst you have now got your own solution you should be aware that this will only be performant in a low volume web site as you are trading web page performance (low amount of viewstate), for server performance (increased memory use on server due to increased session size).

    As the application scales you will reach a tipping point where the server degredation is effecting your application performance more than if you included the state information with the page in viewstate.

     

    Tuesday, April 5, 2011 4:41 AM
  • User858479128 posted

    Yes we are aware of that but putting lists of objects in viewstat will increase page size that will degrade performance of the website especially

    slow connection environment, but if we put it in session I think that list of objects will not have a big size at all,also if we want to manage this

    we can make a state server to manage session state and it will not have performance issues like viewstate

    You reply is very appreciated frez

    Thanks

    Wednesday, April 6, 2011 3:40 AM