locked
Session_End Event RRS feed

  • Question

  • User-827730410 posted

    Hi

    i have one table .. table contains some columns . whenever user will be logged in . then i m update value in database as well as whenever user have logged out

    again i m upadating value in table .. But i have  one doubt user have logged in but he didn't logged out and he closed the application. at time the data base not will be changed. i would like to update the database when the user have closed application time..

    i getting user id  from database and strored into  session varibles in session_start time as well i wrote code(database updation )  in sesson_end event in Global.asx  but

    i have lost session information which i have stored in session varibles..

    any body have an idea plz  help me...

    Thanks
     




     

    Friday, July 13, 2007 2:41 AM

Answers

All replies

  • User1161433742 posted

    Hi,

    Even if the user closes the browser window without logging out of the application, Session_End event is still fired so you will not loose any data. In this case, the Session_End event will be called after Session Timeout has elapsed. Session will be automatically terminated and Session_End event will get fired.

    Friday, July 13, 2007 3:21 AM
  • User-827730410 posted

     hi

    Thanks Sujitm

     Its working fine.. i have one more doubt. i have given session time like

    <system.web>
        <sessionState mode="InProc"  cookieless="false" timeout="10">
        </sessionState>
      </system.web>

    whenever the session timed out then i have to modify my database using user id . But i have stored in Session["Uid"]. So that whenever session_end event rised i will lost Session["Uid"]=null;

    my requirement is whenever session killed or(Session_End event raised) then i have to modification in my database using user id... But here user id stored in Session varible


    Plz give some suggestion ...

    Thanks... 

     

     

     

     

     



     

    Friday, July 13, 2007 6:32 AM
  • User1161433742 posted

    Hi,

    You can use the Page.Cache object to store the value of the Uid. Be very careful when using Page.Cache as Cache is shared across all sessions in ASP.net application. You can use the Session.SessionID as a key for storing the UID of that particular session.

    Friday, July 13, 2007 6:42 AM
  • User-827730410 posted

    i have written code in Global.asax 

        void Session_Start(object sender, EventArgs e)
        {
            //// Code that runs when a new session is started
           
            string uid = Request.QueryString["id1"];
            uid = Decrypt(uid);
            Session["Uid"] = uid;
          }
        private string Decrypt(string uid)
        {
            Byte[] b = Convert.FromBase64String(uid);
            string decryptedUid = System.Text.ASCIIEncoding.ASCII.GetString(b);
            return decryptedUid;
        }

        void Session_End(object sender, EventArgs e)
        {
                  
            SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings.Get("ConnectionString"));
            con.Open();
            string str = "update tbl_Users set LoginStatus=0 where UserId =" + Session["Uid"].ToString();
            SqlCommand cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            cmd.Dispose();
            con.Close();

    Wheneve Session_End event raised then Session["Uid"] =null .

     

    Plz Chk above code , I m new in asp.net   

    Very urgent

    Thanks

    Murali... 

    Friday, July 13, 2007 8:17 AM
  • User1672132137 posted

    Check below link

    Access Session variables in Session_End Event

    HC

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 13, 2007 5:20 PM