Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Loop through a session Object

Avatar of skillilea
skillilea asked on
3 Comments1 Solution1449 ViewsLast Modified:
New to this...
asp.net, C# 4.0

I am trying to loop through an object that I have put into a session for debugging display purposes.

I used this...

        // set the user into a session either loggedin or current
        public static void SetUserInfo(UserInfo User, bool LoggedIn)
            string uType = _currentUser;
            if (LoggedIn){ uType = _loggedInUser;}

            if (HttpContext.Current.Session[uType] != null)
                HttpContext.Current.Session[uType] = User;
                HttpContext.Current.Session.Add(uType, User);

        //return the current UserInfo
        public static UserInfo GetCurrentUser(bool LoggedIn)
            string uType = _currentUser;
            if (LoggedIn) { uType = _loggedInUser; }

            return HttpContext.Current.Session[uType] as UserInfo;

Now this is where I am stuck...

                StringBuilder _sb = new StringBuilder();

                _sb.Append("<b>Current Session Count</b>");
                _sb.Append("Session Count: ");
                _sb.Append("Logged In User: ");
                UserInfo u = UserInfoManager.GetCurrentUser(true);
                _sb.Append("Name: ");
                _sb.Append( u.UserName.ToString() );

                //need to loop here

                _res = _sb.ToString();

I want to display each item...what is a better way?

thanks tons
Avatar of Miguel Oz
Miguel OzFlag of Australia imageSenior Software Engineer
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers