Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2015-02-01
Medium Priority
Last Modified: 2015-02-13
How can I initialize session variables in asp.net 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

by:Michael Fowler
Michael Fowler earned 800 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 1200 total points
ID: 40583349
How can I initialize session variables in asp.net 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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


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

by:Michael Fowler
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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