Session is not letting me remove keys

N

Nathan Sokalski

I have an application that is using Session state. On one page, I use the
Session.Add() method to create the Key/Value pair for the first time. I am
then sent to another page using Response.Redirect(). On the page I am sent
to, I can view the Session's value using Session("mykey"), but it will not
let me remove or modify it. I have tried Session("mykey"),
Session.Remove("mykey"), Session.Clear(), and Session.Abandon(). None of
these seemed to make any change to Session (I have tried checking whether
Session("mykey") has a value using both Session("mykey")="" and
Session("mykey") Is Nothing). When I first go to the page that checks
whether Session("mykey") has a value before using Session.Add(), it does
recognize that is does not have a value. Also, when I tried calling
Session.Abandon() twice by clicking the Button that calls the method, it
seemed to work, but not if I call it twice one immediately after the other.
I have EnableSessionState="True" in the @Page and <pages
enableSessionState="true"> in my Web.config file. Does anybody have any idea
why I might be having this problem? Thanks.

Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Nathan said:
I have an application that is using Session state. On one page, I use
the Session.Add() method to create the Key/Value pair for the first
time. I am then sent to another page using Response.Redirect(). On the
page I am sent to, I can view the Session's value using
Session("mykey"), but it will not let me remove or modify it. I have
tried Session("mykey"), Session.Remove("mykey"), Session.Clear(), and
Session.Abandon(). None of these seemed to make any change to Session (I
have tried checking whether Session("mykey") has a value using both
Session("mykey")="" and Session("mykey") Is Nothing). When I first go to
the page that checks whether Session("mykey") has a value before using
Session.Add(), it does recognize that is does not have a value. Also,
when I tried calling Session.Abandon() twice by clicking the Button that
calls the method, it seemed to work, but not if I call it twice one
immediately after the other. I have EnableSessionState="True" in the
@Page and <pages enableSessionState="true"> in my Web.config file. Does
anybody have any idea why I might be having this problem? Thanks.

The Remove method and the Clear method should absolutely remove the
values from the session variables collection. You must have made some
mistake when using them.

The Abandon method doesn't remove anything from the session object, it
only registers that the session will be abandoned when the request has
been completed. The current Session object is still available during the
execution of the current page. When the next page is requested, a new
Session object will be created.
 
S

sloan

//
The Abandon method doesn't remove anything from the session object, it
only registers that the session will be abandoned when the request has
been completed. The current Session object is still available during the
execution of the current page. When the next page is requested, a new
Session object will be created.
//

Ditto on that. The Abandon will "trick you" until you figure out that it
happens after the execution of the current page.

One of the reasons I wrote this:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!151.entry

was because I had a better Remove and Clear methods to call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top