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:

Troubleshooting
Research
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
C#ASP.NET
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;
            else
                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("<hr>");
                _sb.Append("<b>Current Session Count</b>");
                _sb.Append("<hr>");
                _sb.Append("Session Count: ");
                _sb.Append(HttpContext.Current.Session.Count.ToString());
                _sb.Append("<hr>");
                _sb.Append("Logged In User: ");
                UserInfo u = UserInfoManager.GetCurrentUser(true);
                _sb.Append("Name: ");
                _sb.Append( u.UserName.ToString() );
                _sb.Append("<br>");

                //need to loop here

                _res = _sb.ToString();


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

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