iam making an web application in that when the user login i just assign session to them to login.. when they logout i cleared the session.. but when we click the back and front button in the browser the previous page be loaded after logout.. so here how can i maintain session for each page..
please give me the idea..

Sunny SharmaRank #223 · 11.1K reputationPosted Jul 31, 2013, 2:08 AM EDT
Add this to your Master Page / Base Page- Page_Load:
Response.AddHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
It should work.
Sunny SharmaRank #223 · 11.1K reputationPosted Jul 31, 2013, 12:03 AM EDT
You just don't need to maintain session for all the pages. Just check the Session variable to be true at page_load of or may be on a single master page if you're using Master Page. If the session variable is false then redirect the user to login form. Below is the pattern:
............. Page_Load(....)
{
bool userLoggedIn=false;
try
{
userLoggedIn=(bool)Session["userLoggedIn"];
}
catch { }
if(!userLoggedIn)
{
Response.redirect("Login.aspx");
}
}
------------------
Happy Coding :)
Cheers!
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 12:23 AM EDT
try like this
if you are using Master Page in Page_Load
//the below approch need to follow, since session will expire after defined time(in web.config)
if not master page, then create on base page and check session there
protected override void OnInit(EventArgs e)
private void ValidateSession()
inherit this base page to all your page like this
}
Regards,
Iftikar
iswarya chandran67 reputationPosted Jul 31, 2013, 12:59 AM EDT
am using master page with 2 menus.. first menu having admin login option.. once logged in 2nd menu get appear.. like add profile etc.,
In the master page
if (session["Admin"]="A")
{
menu1.visible=false;
menu2.visible=false;
}
else
{
menu1.visible=false;
menu2.visible=false;
}
In the login page i assigned session as
session["Admin"]="A";
Response.Redirect("~\User.aspx")
and if i give as u said in Add profile page load event, it wont go inside tht page aftr login too..
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 1:05 AM EDT
Regards,
Iftikar
iswarya chandran67 reputationPosted Jul 31, 2013, 2:04 AM EDT
after logging out if i press back button in the browser the previous page will be displayed.
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:09 AM EDT
Regards,
Iftikar
iswarya chandran67 reputationPosted Jul 31, 2013, 2:29 AM EDT
in master page where can i add this code??
iswarya chandran67 reputationPosted Jul 31, 2013, 2:31 AM EDT
yes sir if i cleared browser history it works.. but for me once logged out it should reloaded.. without clearing the browser history too the page should be go to login page..
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 2:36 AM EDT
Regards,
Iftikar
iswarya chandran67 reputationPosted Jul 31, 2013, 3:01 AM EDT
am very thankful to you both for giving me such a wonderful explanations and spend your valuable time with me..
thank you sir..
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 3:07 AM EDT
Regards,
Iftikar
Sunny SharmaRank #223 · 11.1K reputationPosted Jul 31, 2013, 3:24 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jul 31, 2013, 4:32 AM EDT
Regards,
Iftikar