3
votes

I have a login page(default.aspx) followed by 2 asp.net pages(page1.aspx,page2.aspx) under a masterpage with logout button. When I click logout,it makes the session null and hence logout.

But after logging out when I put the url of page1.aspx in the address bar, it displays the page(page1.aspx) again.

My code for logout button:

Session["id"] = null;
Response.Redirect("Default.aspx");
Response.Cache.SetNoStore();
Response.CacheControl = "no-cache";
5

5 Answers

4
votes

you have to use session abandon method Session abandon Session.Abandon ()

3
votes

Try this code:

 Session.Abandon();
 Session.Clear();
 Response.Cookies.Clear();
 Response.Redirect("Default.aspx");
1
votes

First You have to clear Session value and then after redirect to another page

Session["id"] = null;
Session.Clear();
Response.Cookies.Clear();
Response.Cache.SetNoStore();
Response.CacheControl = "no-cache";
Response.Redirect("Default.aspx");
0
votes

You could try deleting the cookie containing the session ID. Like so:

Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
0
votes

As per an earlier answer , you can definitely use Session.Abandon(); and after that you have to check your condition for session values on the particular page load.

if (Session["Name"] == null)
{
    Response.Redirect("Login.aspx");
}