What is the difference between session.clear and session.abandon




















Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. What is the difference between Session. Abandon and Session. Clear Ask Question. Asked 12 years, 1 month ago. Active 4 years, 11 months ago. Viewed k times. I searched for this question, but don't grasp total answer. Some answers are: Session. Abandon destroys the session Session.

Clear just removes all values A friend told me this: Clearing the session will not unset the session, it still exists with the same ID for the user but with the values simply cleared. The below code works and doesn't throw any exceptions. I just find one difference: session. Ryan Gates 4, 5 5 gold badges 47 47 silver badges 86 86 bronze badges.

Add a comment. Active Oldest Votes. If you will use Session. Clear you will have the same session in many requests. Clear removes items immidiately, Abandon does not. Abandon releases the SessionState object and its items so it can ba garbage collected to free the resources. Clear keeps SessionState and resources associated with it. Richard Ev Dmytrii Nagirniak Dmytrii Nagirniak Clear will only remove items from the Session. Nothing more. You can call it as many times as needed.

AnthonyWJones, you are right "destroy" is incorrect to say. But Session. Clear also does not destroy objects, it removes thm from session so they can be garbage collected. Ads I agree, although I would extend it by saying that Session.

Clear can be compared to removing all books from the shelf immediately , while Session. Abandon is more like saying "throw away the whole shelf and let me know when you're done ".

Show 13 more comments. Net uses old session id — backdoor. Hans Kesting He will not get a new Session Id when abandon is called. Why would you need Session. Clear followed by Session. You are clearing values of a collection that you are destroying? This is completely redundant. Sure the session object is not immediately destroyed that happens at the end of the current request , but that session id will no longer be served by any subsequent request.

If the client does make a new request, a new session will be given to them. Asax they won't be there because you cleared them. RepDbg actually I disagree. Abandon , you lose that specific session and the user will get a new session key. You could use it for example when the user logs out.

Use Session. Clear , if you want that the user remaining in the same session if you don't want him to relogin for example and reset all his session specific data. Clear the user must relogin. Clear ". Clear removes all the variables stored in session and if user try to browse your site same sessionID will be used which was previously assigned to him.

Either you call Session. Clear or session. Abandon, user will logout if you are using session to store his login status almost in The content you requested has been removed. Sign in Email. Forgot your password? Ask a Question. When we use Session. Clear and Session. Abandon in asp. Please Sign up or sign in to vote.

See more: ASP. Add a Solution. ZurdoDev Feb am. Depends on business scenarios. Did you lookup what they do? I assume you understand what they do so do you have a more specific question? Top Rated Most Recent. Accept Solution Reject Solution. When the user clicks on Signout or logout we need to clear session. By default session expires after 20 min of ideal state. Posted Feb am Sreekanth Mothukuru. Clear clears the all session variables value whereas Session.

Abandon vanishes kills the session. Please follow the links.. Posted Feb pm AshishChaudha. When you want to clear your session data that time you can call these methods. Some differences are, 1.



0コメント

  • 1000 / 1000