Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys,

I'm working on sessions to trace upon login/logout.. once logout all sessions will be cleared.
n the page will redirect to login page.

but when i click logout, its clear the session but on browser back button click, it will again redirecting to the content page..

My Code for ContectPage:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["logged_user"] != null || Session["user"] != null || Session["menu"] != null)
            {
                if (!IsPostBack)
                {
                    Repeater1.DataSource = DAL.GenericSP_RS(1, "GetUnitTrackingRS", "");
                    Repeater1.DataBind();
                }

            }
            else
            {
                Session["logged_user"] = null;
                Session["user"] = null;
                Session["menu"] = null;
                Session.Abandon();
                Session.Clear();

                Response.Redirect("Login.aspx");

            }

        }


Code for Logout Page:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["logged_user"] != null || Session["user"] != null || Session["menu"] != null)
            {
                if (!IsPostBack)
                {
                    Session["logged_user"] = null;
                    Session["user"] = null;
                    Session["menu"] = null;
                    Session.Abandon();
                    Session.Clear();
                    Response.Redirect("Login.aspx");

                }
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }



plzzzz help me guys, i'm sucked.

thanks
Posted
Comments
Kornfeld Eliyahu Peter 9-Mar-14 4:48am    
Probably your page displayed from cache, so the code not executed. Remove the page from the cache that it should work as expected...

 
Share this answer
 
For no caching in the browser





In page load we will use the below code

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();

One more thing we need to keep in mind that in master content page application, we need to check the username and password for not null in the page load of master page. If null it will always redirect to the login page.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900