session are not getting cleared

Posted by Deepakji under C# on 3/30/2012 | Points: 10 | Views : 1348 | Status : [Member] | Replies : 5
hi, in my project i am using session to maintain users but now when i click logout i am going back to login page but when i am clicking back button of browser i am able to view previous pages but i dont want that if i click back it should go to login page after clicking logout button.so please let me know i am sending the code.

protected void Page_Load(object sender, EventArgs e)
{


Session.Clear();
Session.RemoveAll();
Session["user"] = "";
Session["name"] = "";
Session["user"] = null;
Session["name"] = null;

}
protected void lbHomePage_Click(object sender, EventArgs e)
{
Response.Redirect("LoginPage.aspx");
}




Responses

Posted by: Rajni.Shekhar on: 3/30/2012 [Member] Bronze | Points: 25

Up
0
Down
you can do onething, clear session on application_End or session_end event in global.asax file.

OR

You can write code to clear history in javascript, and call that function while logout.

Thanks,
Rajni Shekhar

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/30/2012 [Member] Bronze | Points: 25

Up
0
Down
Try this:

var Back_length=history.length; history.go(-Back_length);

window.location.href=set your page url here

Thanks,
Rajni Shekhar

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Taanu51 on: 3/30/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ..use the following

Session.Abandon();
Session.Remove("Username");

For more details check this link

http://www.developerscode.com/2011/02/how-to-create-logout-page-using.html

If found the answer ,pls mark as answer

Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/31/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,
just use Session.Abandon() method

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
on sign out or logout use Session.Abandon() ;

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Deepakji, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response