How can I initialize session variables in when I start the application?  All of them without knowing their names in particular.

Posted on 2015-02-01
Last Modified: 2015-02-13
How can I initialize session variables in when I start the application?  All of them without knowing their names in particular.
Question by:goodk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 23

Assisted Solution

Michael74 earned 200 total points
ID: 40583294
If you are looking to loop through the session variables you could use

SessionStateItemCollection items = new SessionStateItemCollection();
foreach (string s in items.Keys)
// Do something

Open in new window

For some more information on session variables have a look at this MSDN page
LVL 75

Accepted Solution

käµfm³d   👽 earned 300 total points
ID: 40583349
How can I initialize session variables in when I start the application?
And how would you expect that to happen? No one is actually using your application at the time it is started by IIS, so there is no session. A session only exists when a user begins interacting with your application. So is what you are asking how to have a default value for a particular set of session values?

Author Comment

ID: 40584743
Thank you guys.  I think I have a deeper problem to solve as some session variables are initialized and another web page tries to use them without being set for that particular web page.  

Not really sure how to address the situation.  Maybe I need to append the page name into the session variable name.
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.


Author Comment

ID: 40584750
Oops, I really wanted to give credit to both the respondents.  Not sure how to correct it.
LVL 23

Expert Comment

ID: 40584893

Don't worry about it, but for interests sake you may want want to have a quick look at the EE help page which has some information on how to accept questions and changing your decision
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40585219
Simply "Request Attention" just below your original question.

Author Closing Comment

ID: 40608435
thanks guys

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question