CrazyEngineers
  • need help for creating session in asp.net

    Updated: Oct 26, 2024
    Views: 1.1K
    i have made 2 pages....1 for login n next to show after successful login....
    on login page i have created a button....in its handler i have created session.... on the load event of next page i m checking for the availibity of the session variable n its value.... its workin well..... but the problem comes when i press back button of the browser.....after signing out when i press back button the page is being displayed.....(this should not happend).... can anyone help me regarding this...?? plz reply soon....
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Mahesh Dahale

    MemberNov 8, 2009

    adding following code in the page load of the page for which we do not want to cache the page in history.

    [COLOR=black][COLOR=black][FONT=Arial][COLOR=black][COLOR=black][FONT=Arial][COLOR=black][COLOR=black][FONT=Arial][COLOR=black][COLOR=black][FONT=Arial][COLOR=black][FONT=Arial][COLOR=black][FONT=Arial][COLOR=black][FONT=Arial][FONT=Times New Roman][FONT=Arial][FONT=Arial][FONT=Arial][FONT=Arial][FONT=Arial][FONT=Arial][FONT=Arial][FONT=Arial][FONT=Arial]Response.Buffer=<SPAN style="COLOR: blue">true;<o:p></o:p>
    Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
    Response.Expires =-1500;
    Response.CacheControl = "no-cache";
     if(Session["SessionId"] == null)
        {
        Response.Redirect ("WdetLogin.aspx");
        }
    }[/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/FONT][/COLOR][/COLOR][/FONT][/COLOR][/COLOR][/FONT][/COLOR][/COLOR][/FONT][/COLOR][/COLOR]
    Or

    Response.CacheControl = "no-cache";
    for session details
    <a href="https://www.w3schools.com/asp/asp_sessions.asp" target="_blank" rel="nofollow noopener noreferrer">ASP Session object</a>
    Are you sure? This action cannot be undone.
    Cancel
  • Mahesh Dahale

    MemberNov 8, 2009

    when logging out you should use
    Session.Abandon();
    Session.Redirect("Login.aspx");
    
    instead of Session["loggedIn"] = false;
    Are you sure? This action cannot be undone.
    Cancel
  • Hima Kapadia

    MemberNov 8, 2009

    haha.... have u tried this code.?? this doesnt work in mozilla.... it only works in IE...
    Are you sure? This action cannot be undone.
    Cancel
  • Mahesh Dahale

    MemberNov 8, 2009

    ok
    Try this java script
    <script type = "text/javascript" >
       function preventBack(){window.history.forward();}
         setTimeout("preventBack()", 0);
         window.onunload=function(){null};
     </script>
    Are you sure? This action cannot be undone.
    Cancel
  • gsxraddict

    MemberNov 19, 2009

    Here, I want you to watch this:

    #-Link-Snipped-#

    Membership roles are a good .net option.
    Are you sure? This action cannot be undone.
    Cancel
  • sarveshgupta

    MemberNov 20, 2009

    protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CS"] != null)
            {
                con.ConnectionString = Session["CS"].ToString();
                com.Connection = con;
                Session.Add("User_Name", null);
                Session.Add("Password", null);
            }
            else
            {
                Response.Redirect("Main Home.aspx");
            }
    
        }
    This will be for the page users visits after looging in

    and on the click of Sign out

      protected void logout_Click(object sender, ImageClickEventArgs e)
        {
            Session["User_Name"] = null;
            Session["Password"] = null;
            Response.Redirect("Default.aspx");
        }
    
    This will help you solve the problem.
    Am I right?
    Are you sure? This action cannot be undone.
    Cancel
  • KurtFanta

    MemberNov 24, 2009

    The following link may be of help to you: <Admin writes: the link's got nothing to do with asp.net. Further spamming may lead to permanent ban on your account>#-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register