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 SharmaPosted Jul 31, 2013, 6:08 AM
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.
Iftikar HussainPosted Jul 31, 2013, 8:32 AM
Regards,
Iftikar
Sunny SharmaPosted Jul 31, 2013, 7:24 AM
Iftikar HussainPosted Jul 31, 2013, 7:07 AM
Regards,
Iftikar
iswarya chandranPosted Jul 31, 2013, 7:01 AM
am very thankful to you both for giving me such a wonderful explanations and spend your valuable time with me..
thank you sir..
Iftikar HussainPosted Jul 31, 2013, 6:36 AM
Regards,
Iftikar
iswarya chandranPosted Jul 31, 2013, 6:31 AM
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..
iswarya chandranPosted Jul 31, 2013, 6:29 AM
in master page where can i add this code??
Iftikar HussainPosted Jul 31, 2013, 6:09 AM
Regards,
Iftikar
iswarya chandranPosted Jul 31, 2013, 6:04 AM
after logging out if i press back button in the browser the previous page will be displayed.
Iftikar HussainPosted Jul 31, 2013, 5:05 AM
Regards,
Iftikar
iswarya chandranPosted Jul 31, 2013, 4:59 AM
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 HussainPosted Jul 31, 2013, 4:23 AM
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
Sunny SharmaPosted Jul 31, 2013, 4:03 AM
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!