Results 1 to 20 of 20

Thread: [RESOLVED] SessionID question

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Resolved [RESOLVED] SessionID question

    Hello Everybody,

    I have an ASP.NET page that has a wizard control. I need to see if the same user is working on the page so I first time I insert a record and next time I update database records. I am using Session.SessionID to check if the same user is working on the page, but on every postback, SessionID gives a unique string and always the "insert" construct executes.

    What is the best way to check the same user is working back and forth on the same page. User is not logged in, its an open form on the page.

    Thanks.

  2. #2
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: SessionID question

    hay,
    i hardly can understand what you mean can you clear things more?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: SessionID question

    usamaalam,

    I think you are going to need to show some of the code that you are using?

    Gary

  4. #4

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: SessionID question

    Yes sure.

    I have a page where there is a form. The form is in 12 steps. The user fills in the first step and click Next, on the click of Next button I "insert" the data in the database. On step 2, the user fills in the form and this time I need to "update" the database record that was previously entered in the step 1. Similarly, user may click back button and go again on step 1, change the data and click Next. This time again record should be "updated".

    In my database table, I added one field called "SessionID". When first time I insert record, I also insert Session.SessionID in this field. Next time I check if Session.SessionID = SessionID (in database) I update the record. But Session.SessionID always gives me a new value.

    I need a value that should remain the same for that user throughout his working on the page.

    Thanks.

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: SessionID question

    What sort of information are you inserting into this table? Do you have any concept of user membership? If so, I think the Profile Provider might be able to provide you with what you need.

    The technique that you are using though is definitely valid, so I am curious to see the code that you are using to see where it could be going wrong.

    Gary

  6. #6
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: SessionID question

    hay,
    actually why you doing all of this,
    from your first step, you successfully inserted your row, which mean you have your primary key for this row, you can store this value in your session,
    and update your row according to your row in the next step using the stored value for the primary key in your session.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  7. #7
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: SessionID question

    Quote Originally Posted by avrail View Post
    hay,
    actually why you doing all of this,
    from your first step, you successfully inserted your row, which mean you have your primary key for this row, you can store this value in your session,
    and update your row according to your row in the next step using the stored value for the primary key in your session.
    The point that he is making is that the SessionID, which is his primary key, is changing, even though it is the same user.

    The only reason this should happen is if the application pool gets recycled, or if the session expires.

    Gary

  8. #8

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: SessionID question

    The problem is just resolved. Session.SessionID was not persistent but when I saved something in a session variable, it works great. I added the following line on my page load event and now I get same value of Session.SessionID on every postback.

    Code:
    Session["Test"] = "Test";
    Do you want me to put the rest of the code here?

    Thanks a lot.

  9. #9
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: SessionID question

    Quote Originally Posted by gep13 View Post
    The point that he is making is that the SessionID, which is his primary key, is changing, even though it is the same user.

    The only reason this should happen is if the application pool gets recycled, or if the session expires.

    Gary
    sure if the session ID changed, and the user are the same, then his session id must be expires,
    but he didn't actually said that he using the SessionID as a primary key ?? did you usamaalam?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  10. #10
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: SessionID question

    Hey,

    This is definitely the way to go.

    Either create a Session object for each "thing" you need to remember, or create a class that represents everything that you need, and put this into a Session variable.

    I am still surprised that Session.SessionID is giving different results though?!?!

    If you have got it working, then no need to upload the rest of your code.

    Gary

  11. #11
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: SessionID question

    hay usamaalam,
    please are you using the SessionID as a Primary key for your table ?
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  12. #12

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: SessionID question

    I was surprised too, I took a simple plane page and put the following line in page load and was getting a new value on every refresh.

    Code:
    string sessionID = Session.SessionID;
    Thanks avrail and gep13 for all your help.

  13. #13

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: SessionID question

    Quote Originally Posted by avrail View Post
    hay usamaalam,
    please are you using the SessionID as a Primary key for your table ?
    Yes I am using SessionID as candidate key.

  14. #14
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: SessionID question

    amm, so please gep correct me if i was wrong,
    is there any possibility this SessionID be the same after sometime, let us say month??
    actually i don't know the mechanism that session id created by.
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  15. #15
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: SessionID question

    On a side note, you might want to take a look at the following:

    http://msdn.microsoft.com/en-us/libr...ewsession.aspx

    Gary

  16. #16
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: SessionID question

    Quote Originally Posted by avrail View Post
    amm, so please gep correct me if i was wrong,
    is there any possibility this SessionID be the same after sometime, let us say month??
    actually i don't know the mechanism that session id created by.
    That really comes down to how Session is configured on the server. It is possible to extend the Session timeout, but for a time period of a month, you would be looking to persist that information somewhere else, not in Session.

    Gary

  17. #17
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: [RESOLVED] SessionID question

    no, you misunderstand me
    primary key is Unique,
    what if your sessionID inserted into the database as a primary key, and after a month someone else used the page, and he has a new SeesionID, can we grantee this new SessionID not used before ???
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  18. #18

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: [RESOLVED] SessionID question

    Quote Originally Posted by avrail View Post
    no, you misunderstand me
    primary key is Unique,
    what if your sessionID inserted into the database as a primary key, and after a month someone else used the page, and he has a new SeesionID, can we grantee this new SessionID not used before ???
    Actually in my case, I just need to save the data, perform very little calculation, email the result and the data is then useless and will never be fetched. This is why I don't care if SessionID is repeated, since I am comparing SessionID plus Today's date.

    Thanks.

  19. #19
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: [RESOLVED] SessionID question

    that's good for you
    but i still care, is it a sessionId unique for ever or for some reason it will be repeated ?
    i love this Q
    any way it is not a big deal
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  20. #20
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] SessionID question

    If I had to guess, I would say that this is something to do with the use of the ASP.Net Development Server. I would be curious to know if this happened on a web application under IIS.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width