troubleshooting Question

Loop through a session Object

Avatar of skillilea
skillilea asked on
ASP.NETC#
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
Miguel Oz
Senior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2009

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros