need help for creating session in asp.net

Hima Kapadia

Hima Kapadia

@hima-kapadia-917ytW Oct 26, 2024
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....

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Mahesh Dahale

    Mahesh Dahale

    @mahesh-E2tZ3t Nov 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>
  • Mahesh Dahale

    Mahesh Dahale

    @mahesh-E2tZ3t Nov 8, 2009

    when logging out you should use
    Session.Abandon();
    Session.Redirect("Login.aspx");
    
    instead of Session["loggedIn"] = false;
  • Hima Kapadia

    Hima Kapadia

    @hima-kapadia-917ytW Nov 8, 2009

    haha.... have u tried this code.?? this doesnt work in mozilla.... it only works in IE...
  • Mahesh Dahale

    Mahesh Dahale

    @mahesh-E2tZ3t Nov 8, 2009

    ok
    Try this java script
    <script type = "text/javascript" >
       function preventBack(){window.history.forward();}
         setTimeout("preventBack()", 0);
         window.onunload=function(){null};
     </script>
  • gsxraddict

    gsxraddict

    @gsxraddict-r5vh86 Nov 19, 2009

    Here, I want you to watch this:

    #-Link-Snipped-#

    Membership roles are a good .net option.
  • sarveshgupta

    sarveshgupta

    @sarveshgupta-txtmu5 Nov 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?
  • KurtFanta

    KurtFanta

    @kurtfanta-ypcsah Nov 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-#