One easy way to solve this problem is applying javascript. It would not allow a person to go back to that page. But, is it a feasible solution? NO! One would like to go back, even after logout to see something. This javascript would disable to come back. So, that is not a proper solution.
So, here I am writing the proper code, which we finally found out and happy news is that, “It really works!”. So just follow this code.
If you applying a MasterPage, then copy these codes to its page load, or copy to that page’s load, which comes after login page or comes before logout page.

And on logout button click, write these codes.

So, if you still getting some kind of problem, please leave comment.
If you liked this article, please rate and comment. Thank You!
It works fine…..Thanks a lot
Dude you are the only blogger who wrote correct solution for this problem. thanks for your help.
Thank you guys! Am so happy to help you even a little bit. π
thanks brother i also have that problem but i could not reach the solution
Thanks ,,, Thank u very much….
it works well …
but still 1 problem
While Login perform some task to other pages and logout, till that ok now if i press back button Error is [Document Expire (Cache problem)]
Only One Problem Left … !!!
Please Help Me Out…
Dear @Jimmy, have you gone though all the steps? Remember to put the code into either on master’s load or the page which comes after login.
Its not working for me i have followed same steps still after logout when i press back button its going back to the previous page
Dear friend, I am done my best to solve this problem. Please cross check once. You must be forgetting something. Please assure that you have pasted the code in the right place. And the variable I have for Session are same or changed according to your codes. Like Session[“user_id”]= null; You have to replace user_id with your parameter. Rest check the pages where you have pasted the codes. Please provide more information if problem not solved.
cheers mate..god bless you..keep up good work π
Thank you dear friend!! Its worth than anything. π
really awesome friend………. really thank u thank u sooooo muchhhhhhh
Thank you dear friend for appreciating..:)
Friend I log out successfully but when i click on back button there are show again welcome page. i don’t want to show this page after log out when i click on back button of browser.Please help me
The above solution will help you. Just follow the instruction and copy the codes in respective pages. π
Thank’s
String q = “SELECT * FROM login WHERE username='” + TextBox1.Text + “‘ AND password='”+TextBox2.Text+”‘”;
SqlConnection con = new SqlConnection(“Data Source=ankita-pc;Initial Catalog=portal;Integrated Security=True”);
con.Open();
SqlCommand com = new SqlCommand(q, con);
SqlDataReader read;
read = com.ExecuteReader();
read.Read();
u_name = read.GetValue(0).ToString();
pass = read.GetValue(1).ToString();
read.Close();
con.Close();
HttpCookie id1 = new HttpCookie(“u_name”);
// HttpCookie pass1 = new HttpCookie(“pass”);
id1.Value = u_name;
//pass1.Value = pass;
Response.Cookies.Add(id1);
// Response.Cookies.Add(pass1);
if (u_name != ” ” & pass != ” “)
{
Response.Redirect(“default.aspx”);
}
}
this is my login page code
protected void Page_Load(object sender, EventArgs e)
{
DateDisplay.Text = DateTime.Now.ToString(“dddd, MMMM dd”);
L_id.Text = Request.Cookies[“u_name”].Value.ToString();
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Session.Abandon();
FormsAuthentication.SignOut();
Session[“username”] = null;
Session[“password”] = null;
Response.Redirect(“login.aspx”);
}
this is my logout page code…..but not working
thanks a lot your code is working fine.
My pleasure. Thank for visiting my blog. π
public partial class Adminpanel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session[“id”] != null)
{
Response.Write(“HELLO”);
}
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
}
protected void Button1_Click(object sender, EventArgs e)
{
Session.Abandon();
FormsAuthentication.SignOut();
Session[“id”] = null;
Session[“Pass”] = null;
Response.Redirect(“~/login.aspx”);
}
}
HERE IS MY CODE.
and this is not working. Please check it what’s the problem in my code. Thank you
Cheers Mate. God bless you