Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Some problem in session (may be..) [modified]

Some problem in session (may be..) [modified]

Scheduled Pinned Locked Moved ASP.NET
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dev S
    wrote on last edited by
    #1

    Hi, I have a website in which users are assigned userid and they have to save their daily report in the site after logging in. I keep userid in session variable and while saving the data it is also saved in the report table. But yesterday what happened a user when saved his report, it was saved with other user's id. I also make a log of user login time and in it the login time of both users is also not same even it has difference of hours. Can anyone help me out why it happened? and how could i apply measures so that it would not happen in future.. Abhijit, Yusuf or anyone else there who could help me..

    modified on Thursday, April 9, 2009 3:24 AM

    A 1 Reply Last reply
    0
    • D Dev S

      Hi, I have a website in which users are assigned userid and they have to save their daily report in the site after logging in. I keep userid in session variable and while saving the data it is also saved in the report table. But yesterday what happened a user when saved his report, it was saved with other user's id. I also make a log of user login time and in it the login time of both users is also not same even it has difference of hours. Can anyone help me out why it happened? and how could i apply measures so that it would not happen in future.. Abhijit, Yusuf or anyone else there who could help me..

      modified on Thursday, April 9, 2009 3:24 AM

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      devesh sinha wrote:

      But yesterday what happened a user when saved his report, it was saved with other user's id.

      May be it can be cause of session problem. How did you clean up the session while log off from the application ? And What data they are saving ?

      cheers, Abhijit CodeProject MVP

      D 1 Reply Last reply
      0
      • A Abhijit Jana

        devesh sinha wrote:

        But yesterday what happened a user when saved his report, it was saved with other user's id.

        May be it can be cause of session problem. How did you clean up the session while log off from the application ? And What data they are saving ?

        cheers, Abhijit CodeProject MVP

        D Offline
        D Offline
        Dev S
        wrote on last edited by
        #3

        On logout user is redirected to homepage where i have removed all the session variable and also in Global.asax.cs I have removed session and application at session_end. Data saved by users is their daily work report. I have also made a fucntion to check session on each page and in case it is expired user is redirected to login page.

        A 1 Reply Last reply
        0
        • D Dev S

          On logout user is redirected to homepage where i have removed all the session variable and also in Global.asax.cs I have removed session and application at session_end. Data saved by users is their daily work report. I have also made a fucntion to check session on each page and in case it is expired user is redirected to login page.

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          Devesh, can you please put the code for Data Save Section , and Log Out Section?

          cheers, Abhijit CodeProject MVP

          D 1 Reply Last reply
          0
          • A Abhijit Jana

            Devesh, can you please put the code for Data Save Section , and Log Out Section?

            cheers, Abhijit CodeProject MVP

            D Offline
            D Offline
            Dev S
            wrote on last edited by
            #5

            After checkin some condition this code comes. I ahve used a stored procedure to save the data and the userid is passed through a variable "usrid" which i assigned the value on top from the session variable.

            SqlConnection con = cmn.getcon(); //new SqlConnection(constr);
            if (con.State == ConnectionState.Open)
            con.Close();
            con.Open();
            SqlDateTime sqldatenull;
            sqldatenull = SqlDateTime.Null;
            SqlCommand cmd = new SqlCommand("usp_OrderMaster_Ins", con);
            cmd.CommandType = CommandType.StoredProcedure;

                        string a = txtVisitHr1.Text.ToString();
                        string b = txtVisitMin1.Text.ToString();
            
                        // Define Parameters
            
                        cmd.Parameters.Add("@VisitDate", SqlDbType.DateTime, 8).Value = cmn.MMDDYYtoYYMMDD(txtVisitDate1.Text);
            
                        // --------------Stop After Discussion with Anand and G.Shyam Sundar -------------------------
            
                        // cmd.Parameters.Add("@VisitTime", SqlDbType.DateTime, 8).Value = txtVisitHr1.Text.ToString() + ":" + txtVisitMin1.Text.ToString() + " " + ddlAMPM.SelectedValue.ToString();
            
                        // -----------------------------------------------------------------------------------------
            
                        cmd.Parameters.Add("@VisitType", SqlDbType.Char, 1).Value = ddlVisitType1.SelectedValue.ToString();
                        cmd.Parameters.Add("@Usr\_ID", SqlDbType.Int, 4).Value = Convert.ToInt32(**usrid**);
                        cmd.Parameters.Add("@FinYr", SqlDbType.Char, 7).Value = cmn.FinYr();
            
                        //change to session userid
            
                        cmd.Parameters.Add("@OutledId", SqlDbType.Int, 4).Value = ddlPartner1.SelectedValue;
            
                        int itmcnt = gdOrderDetails.Items.Count;
            
                        string ordst = "";
            
                        if (itmcnt > 0)
                        {
                            ordst = "Y";
                        }
                        else
                        {
                            ordst = "N";
                        }
            
                        cmd.Parameters.Add("@OrderStatus", SqlDbType.Char, 1).Value = ordst;
            
                        if (txtNextVisitDt1.Text.ToString() == "")
                        {
                            cmd.Parameters.Add("@NextVisitDate", SqlDbType.DateTime, 8).Value = sqldatenull;
                        }
                        else
                        {
                            cmd.Parameters.Add("@NextVisitDate", SqlDbType.DateTime, 8).Value = cmn.MMDDYYtoYYMMDD(txtNextVisitDt1.Text.ToS
            
            A 1 Reply Last reply
            0
            • D Dev S

              After checkin some condition this code comes. I ahve used a stored procedure to save the data and the userid is passed through a variable "usrid" which i assigned the value on top from the session variable.

              SqlConnection con = cmn.getcon(); //new SqlConnection(constr);
              if (con.State == ConnectionState.Open)
              con.Close();
              con.Open();
              SqlDateTime sqldatenull;
              sqldatenull = SqlDateTime.Null;
              SqlCommand cmd = new SqlCommand("usp_OrderMaster_Ins", con);
              cmd.CommandType = CommandType.StoredProcedure;

                          string a = txtVisitHr1.Text.ToString();
                          string b = txtVisitMin1.Text.ToString();
              
                          // Define Parameters
              
                          cmd.Parameters.Add("@VisitDate", SqlDbType.DateTime, 8).Value = cmn.MMDDYYtoYYMMDD(txtVisitDate1.Text);
              
                          // --------------Stop After Discussion with Anand and G.Shyam Sundar -------------------------
              
                          // cmd.Parameters.Add("@VisitTime", SqlDbType.DateTime, 8).Value = txtVisitHr1.Text.ToString() + ":" + txtVisitMin1.Text.ToString() + " " + ddlAMPM.SelectedValue.ToString();
              
                          // -----------------------------------------------------------------------------------------
              
                          cmd.Parameters.Add("@VisitType", SqlDbType.Char, 1).Value = ddlVisitType1.SelectedValue.ToString();
                          cmd.Parameters.Add("@Usr\_ID", SqlDbType.Int, 4).Value = Convert.ToInt32(**usrid**);
                          cmd.Parameters.Add("@FinYr", SqlDbType.Char, 7).Value = cmn.FinYr();
              
                          //change to session userid
              
                          cmd.Parameters.Add("@OutledId", SqlDbType.Int, 4).Value = ddlPartner1.SelectedValue;
              
                          int itmcnt = gdOrderDetails.Items.Count;
              
                          string ordst = "";
              
                          if (itmcnt > 0)
                          {
                              ordst = "Y";
                          }
                          else
                          {
                              ordst = "N";
                          }
              
                          cmd.Parameters.Add("@OrderStatus", SqlDbType.Char, 1).Value = ordst;
              
                          if (txtNextVisitDt1.Text.ToString() == "")
                          {
                              cmd.Parameters.Add("@NextVisitDate", SqlDbType.DateTime, 8).Value = sqldatenull;
                          }
                          else
                          {
                              cmd.Parameters.Add("@NextVisitDate", SqlDbType.DateTime, 8).Value = cmn.MMDDYYtoYYMMDD(txtNextVisitDt1.Text.ToS
              
              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              devesh sinha wrote:

              Logout Section:- On logout user is redirected to homepage where on page load this code is written: Session["Usr_Id"]="no"; Session["Section"] = "";

              Try to do it in Log Out button Click

              try
              {
              Session.Abandon();
              Response.Redirect("Home.aspx", false);

                  }
                  catch (Exception ex)
                  {
                      
                  }
              

              And nothing to do with global.asax until and unless you want to some other stuff while log off. Session.Abandon() will do all stuff for you. :) Hope this will help you :)

              cheers, Abhijit CodeProject MVP

              D 1 Reply Last reply
              0
              • A Abhijit Jana

                devesh sinha wrote:

                Logout Section:- On logout user is redirected to homepage where on page load this code is written: Session["Usr_Id"]="no"; Session["Section"] = "";

                Try to do it in Log Out button Click

                try
                {
                Session.Abandon();
                Response.Redirect("Home.aspx", false);

                    }
                    catch (Exception ex)
                    {
                        
                    }
                

                And nothing to do with global.asax until and unless you want to some other stuff while log off. Session.Abandon() will do all stuff for you. :) Hope this will help you :)

                cheers, Abhijit CodeProject MVP

                D Offline
                D Offline
                Dev S
                wrote on last edited by
                #7

                Abhijit here what i think is the same session shared by two users. So how to prevent that? As in my case one user is logged in into his account, there it was ok even on welcome message i can see his username appearing but while saving the data other user's id was passed. I think it is beacuse of sharing of same session by two users and this thing happened for the first time after more than 1000 entries. What u say about this??

                A 1 Reply Last reply
                0
                • D Dev S

                  Abhijit here what i think is the same session shared by two users. So how to prevent that? As in my case one user is logged in into his account, there it was ok even on welcome message i can see his username appearing but while saving the data other user's id was passed. I think it is beacuse of sharing of same session by two users and this thing happened for the first time after more than 1000 entries. What u say about this??

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #8

                  devesh sinha wrote:

                  what i think is the same session shared by two users.

                  For every client session is unique. How the user are sharing session in your case? I am not clear.

                  devesh sinha wrote:

                  but while saving the data other user's id was passed.

                  check and verify the logic where you are retrieving data from session.

                  devesh sinha wrote:

                  think it is beacuse of sharing of same session by two users and this thing happened for the first time after more than 1000 entries.

                  :confused:

                  cheers, Abhijit CodeProject MVP

                  D 1 Reply Last reply
                  0
                  • A Abhijit Jana

                    devesh sinha wrote:

                    what i think is the same session shared by two users.

                    For every client session is unique. How the user are sharing session in your case? I am not clear.

                    devesh sinha wrote:

                    but while saving the data other user's id was passed.

                    check and verify the logic where you are retrieving data from session.

                    devesh sinha wrote:

                    think it is beacuse of sharing of same session by two users and this thing happened for the first time after more than 1000 entries.

                    :confused:

                    cheers, Abhijit CodeProject MVP

                    D Offline
                    D Offline
                    Dev S
                    wrote on last edited by
                    #9

                    Ya i agree with you this thing has also puzzled me. But i dont find any problem in the logic. I am saving the userid to database which i retrieve from the session so how it is possible that other user's id is fetched while saving whereas the user is seeing all the information related to him on the screen but on saving the data it goes it other person account.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups