I have a aspx page having 2 textboxes for username and password.At submit button click,it is getting redirect to another page.This page has 2 buttons named “Expire Session” and “Go to profile Page”. Now clicking on second button gets the user to another page where he can see the content of this page.I want when the user click expire session button,the session should be expired and then when user will click on the “Go to profile Page” button,he will be redirected to page but no content will be visible because session is over now.
This is Submit button coding .
protected void clicked(object sender, System.EventArgs e)
{
Session["username"] = textbox_username.Text.ToString();
Session["password"] = textbox_password.Text.ToString();
message.Text = "Session saved!";
textbox_username.Text = null;
textbox_password.Text = null;
Response.Redirect("SessionTest.aspx");
}
I do not know how to expire the session at “Expire Session” button click.I am a newbie.
Short answer for short question :
Use
Session.Clear();before above code, if you want to clean session values, but with aSession.Abandon();you will destroy it.Check session with