[RESOLVED] I've tried clearing session but the session is still there. What could be happ[2005]
// Clear all session variables
Session.Clear();
// Removes a particular session variable
Session.Contents.Remove("LoggedIn");
Session["LoggedIn"] = "false";
Session["CurrentUser"] = null;
Session["CurrentPass"] = null;
Session.Abandon();
I've tried these all to no avail. I am wondering what could be causing a page to recreate the session. But first, any of these right? I just don't understand why when I click the link that the variables aren't clearing. Here's the code I am using in the link button.
protected void registerlnkbttn_Click(object sender, EventArgs e)
{
// Clear all session variables
//Session.Clear();
// Removes a particular session variable
//Session.Contents.Remove("LoggedIn");
//Session["LoggedIn"] = "false";
//Session["CurrentUser"] = null;
//Session["CurrentPass"] = null;
//Session.Abandon();
// Reset pages back to non logged in state
loginlnkbttn.Text = "Log In";
loginlnkbttn.PostBackUrl = "login.aspx";
registerlnkbttn.Text = "Register";
registerlnkbttn.PostBackUrl = "register.aspx";
}
}
Re: I've tried clearing session but the session is still there. What could be happ[2005]
Are they being created in the page_load of any pages? In the base page class perhaps?
Re: I've tried clearing session but the session is still there. What could be happ[20
Great suggestion.
Ok, I can see that the session does get cleared during testing. But it only happens when I click the log out link twice.
I can't figure out how to have one link be able to do two different redirects based on what the link reads. I am thinking hte only way to solve this two click link to force the proper refresh is by using a page redirect.
The link button changes from one link to another link based on whether there is a session. So how can I make this one linkbutton choose which page to redirect to?
I mean, between two choice/pages.
Ugh, doesn't matter, redirect is not solving the problem.
Re: I've tried clearing session but the session is still there. What could be happ[20
Quote:
Originally Posted by mendhak
Are they being created in the page_load of any pages? In the base page class perhaps?
I'm going to look it all over again and see if that's the possible problem.
Re: I've tried clearing session but the session is still there. What could be happ[2005]
Well, it is going through that code during debug.
The thing is, it doesn't go through it until the second time I click the log out link.
It skips that code the first time I click the link even though it does change pages to the urlpostback link that the linkbutton is set to. So when I do click the log out link a second time. The session does clear.
It's some weird thing like the problem I had with cookies before where the cookie wouldn't change until the second time I clicked the link.
It had something to do with the update occurs on the server, but not the browser until the update would then be sent to the browser after the second click. But that was with cookies, not sure if something similar could be applying here with the session.
Re: I've tried clearing session but the session is still there. What could be happ[2005]
Got it, redirecting worked out to be the answer. It somehow started to flush the session variables.