How to stop Page being cached
-
Hello All, How to avoid page being cached. Actually i'm creating an Admin Panel so as i click on Log Out button it brings me over the Default page for Log-in again. But the back button of the browser still working and i want to stop it. For it i'm using the following code. But page is still being cached. Response.Buffer = true; Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d); Response.Expires =-1500; Response.CacheControl = "no-cache";
-
Hello All, How to avoid page being cached. Actually i'm creating an Admin Panel so as i click on Log Out button it brings me over the Default page for Log-in again. But the back button of the browser still working and i want to stop it. For it i'm using the following code. But page is still being cached. Response.Buffer = true; Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d); Response.Expires =-1500; Response.CacheControl = "no-cache";
there are meta tags you could use, or since you're logged in i assume there is some sort of session varible involved, which could be checked for on page load, and removed on logout, so that if the var isnt present anymore(it expired, or the user logged out) it would redirect to the login screen.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
there are meta tags you could use, or since you're logged in i assume there is some sort of session varible involved, which could be checked for on page load, and removed on logout, so that if the var isnt present anymore(it expired, or the user logged out) it would redirect to the login screen.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
Here i'm sending my all code for checking at page load still it's not working if (!Page.IsPostBack) { Response.Buffer = true; Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d); Response.Expires =-1500; Response.CacheControl = "no-cache"; if (Session["UserName"] != null) { try { lblMsg.Text = Session["Type"].ToString()+" ("+ Session["UserName"].ToString()+")"; } catch { Server.Transfer("../Admin/Default.aspx"); } } else { Server.Transfer("../Admin/Default.aspx"); } }
-
Here i'm sending my all code for checking at page load still it's not working if (!Page.IsPostBack) { Response.Buffer = true; Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d); Response.Expires =-1500; Response.CacheControl = "no-cache"; if (Session["UserName"] != null) { try { lblMsg.Text = Session["Type"].ToString()+" ("+ Session["UserName"].ToString()+")"; } catch { Server.Transfer("../Admin/Default.aspx"); } } else { Server.Transfer("../Admin/Default.aspx"); } }
I use Response.Redirect instead of Server.Transfer..which seems to be a general consensus but the reason why escapes me at the moment. You dont want to put your session checking code in a !postback block. you want to check every time so that when the session expires you dont get Null reference exceptions if its used outside of a try catch. what you have should work for the first time a page loads, but wont if the user does anything while they're on that page. what happens if you get rid of the !Page.IsPostBack if statement, and run the Response lines and the if(Session["UserName"] != null on every page load?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
I use Response.Redirect instead of Server.Transfer..which seems to be a general consensus but the reason why escapes me at the moment. You dont want to put your session checking code in a !postback block. you want to check every time so that when the session expires you dont get Null reference exceptions if its used outside of a try catch. what you have should work for the first time a page loads, but wont if the user does anything while they're on that page. what happens if you get rid of the !Page.IsPostBack if statement, and run the Response lines and the if(Session["UserName"] != null on every page load?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Sry sir i m not understanding plz explain a bit more............and i think i've already put my code here
you have
if (!Page.IsPostBack)
{
Response.Buffer = true;
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";if (Session["UserName"] != null)
{
try
{
lblMsg.Text = Session["Type"].ToString()+" ("+ Session["UserName"].ToString()+")";
}
catch
{
Server.Transfer("../Admin/Default.aspx");
}
}
else
{
Server.Transfer("../Admin/Default.aspx");
}
}correct? what you might try is
Response.Buffer = true;
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";if (Session["UserName"] != null && Session["Type"] != null)
{
lblMsg.Text = Session["Type"].ToString()+" ("+ Session["UserName"].ToString()+")";
}
else
{
Response.Redirect("../Admin/Default.aspx");
}you only need to have type in the if statement if there is a chance it could be null whitout the UserName bieng null. notice that there is no if(!Page.IsPostBack) statement, this way the code will run EVERY postback, if the session times out and the user tries something they will be redirected to the login(i assume default.aspx is your login page, if its in the same directory as the current page you dont need the relative path just Default.aspx) the nocache options are always set so the back button is effectivly broken(provided they work correctly). this should work, but if the nocache part doesnt, try using meta tags instead.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
you have
if (!Page.IsPostBack)
{
Response.Buffer = true;
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";if (Session["UserName"] != null)
{
try
{
lblMsg.Text = Session["Type"].ToString()+" ("+ Session["UserName"].ToString()+")";
}
catch
{
Server.Transfer("../Admin/Default.aspx");
}
}
else
{
Server.Transfer("../Admin/Default.aspx");
}
}correct? what you might try is
Response.Buffer = true;
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";if (Session["UserName"] != null && Session["Type"] != null)
{
lblMsg.Text = Session["Type"].ToString()+" ("+ Session["UserName"].ToString()+")";
}
else
{
Response.Redirect("../Admin/Default.aspx");
}you only need to have type in the if statement if there is a chance it could be null whitout the UserName bieng null. notice that there is no if(!Page.IsPostBack) statement, this way the code will run EVERY postback, if the session times out and the user tries something they will be redirected to the login(i assume default.aspx is your login page, if its in the same directory as the current page you dont need the relative path just Default.aspx) the nocache options are always set so the back button is effectivly broken(provided they work correctly). this should work, but if the nocache part doesnt, try using meta tags instead.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Same probs But if i put the code given below is working fine in Internet Explorer but not in Flock and Netscape <%@ OutputCache Location="none" %> Now please suggest wht's the problem
i dotn respond well to orders, when i'm trying to help someone regarless of how politely they're given. i've suggested that if changing values in the response object doesnt work to try meta tags, its what i use and they work perfectly, any decent developer would have tried the suggestion or at least mentioned trying it and having problems if it didnt work, i , for the last time, recomend you do a google search about disabling page cashing and try out what you find which should include several options that work in several browsers.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
Hello All, How to avoid page being cached. Actually i'm creating an Admin Panel so as i click on Log Out button it brings me over the Default page for Log-in again. But the back button of the browser still working and i want to stop it. For it i'm using the following code. But page is still being cached. Response.Buffer = true; Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d); Response.Expires =-1500; Response.CacheControl = "no-cache";
-
where is to put this line of code u've given Actually i'm using Master Page and Content Page so should i keep this line of code in Master Page if yes i've done it but same output getting working in Internet Explorer but not in Flock and Netscape Navigator