Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 482603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:06:47+00:00 2026-05-13T01:06:47+00:00

I am sure that I have made some painfully obvious blunder(s) that I just

  • 0

I am sure that I have made some painfully obvious blunder(s) that I just cannot see. I am hoping one of you can set me straight.

I my session management is working perfectly except that if a user on one machine enters data, a user who starts a session on another machine will also retreive the session information from the first. Not so good. 🙁

I call my sessions like this:

UserInfo userinfo = UserInfo.Session;

My session mgt class uses this:

static UserInfo userInfo;

static public UserInfo Session
{
    get
    {
        if (userInfo == null)
        {
            userInfo = new UserInfo();
            userInfo.ResetSessionTime();
        }
        return userInfo;
    }
}

I read and write the data like this. I realize that I could serialize the entire class, but it seems like a lot more overhead to serialize and deserialize an entire class each time the class is called as opposed to just grabbing the one or two items I need.

Decimal _latitude;
private String SessionValue(String sKey, String sValue, String sNewValue)
    {
        String sRetVal = "";
        if (sNewValue == null)//not wanting to update anything
        {
            if (sValue == null)//there is no existing value
            {
                sRetVal = (String)System.Web.HttpContext.Current.Session[sKey];
            }
            else
            {
                sRetVal = sValue;
            }
        }
        else
        {
            System.Web.HttpContext.Current.Session[sKey] = sNewValue;
            sRetVal = sNewValue;
        }
        return sRetVal;
    }



    public Decimal Latitude
    {
        get { return SessionValue("Latitude", _latitude); }
        set { _latitude = SessionValue("Latitude", _latitude, value); }
    }

Thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:06:47+00:00Added an answer on May 13, 2026 at 1:06 am

    1) You’re using statics for your UserInfo, which means that a single instance of this class is shared among all requests coming to your web server.

    2) You’re not only storing values in the session (which isn’t shared among users) but also in an instance variable, which in this case WILL be shared among users.

    So the value of _latitude is causing you this issue. A simple solution is this:

    public class Userinfo
    {
        public Decimal Latitude
        {
            get { return System.Web.HttpContext.Current.Session["Latitude"]; }
            set { System.Web.HttpContext.Current.Session["Latitude"] = value; }
        }
    }
    

    A better, more testable version would be:

    public class UserInfo
    {
        private HttpSessionStateWrapper _session;
        public UserInfo(HttpSessionStateWrapper session)
        ( 
           // throw if null etc
           _session = session;
        )
    
        public Decimal Latitude
        {
            get { return _session["Latitude"]; }
            set { _session["Latitude"] = value; }
        }
    }
    

    In the second instance, within a request you just construct a new instance of the HttpSessionStateWrapper (using the current Session) and pass it to the UserInfo instance. When you test, you can just pass in a mock Wrapper.

    No matter what, the UserInfo instance shouldn’t be shared among sessions and it should write and read directly from the Session. Don’t try to prematurely optimize things by keeping local versions of your session values. You aren’t saving any time and you’re just opening yourself up to bugs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use file_get_contents.I have made sure that allow_url_fopen is enabled in
I'm using subversion so that I can have two checkouts, one for testing to
I have a public amazon AMI that I created. I have made some changes
I have made a script that run various loops and does some SQL inserts.
I am sure that this kind of questions must have been asked before, but
I have a user model on which I check to make sure that the
I have been trying to test my application to make sure that all the
I have this function I'm using and I want to be sure that it
I have the below coding, i am make sure that if condition is TRUE,
I have a simple question, but I'm about 80% sure that the answer to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.