Deekor
Deekor

Reputation: 9499

Session variable in c#?

Is there a way to have something similar to a web session in c#?

For example if I set a integer somewhere integer id = 5; Could I access that integer at a later time in a different class?

I am writing an app that communicates with a web service and I need to keep the id of the authenticated user around for queries to the web.

Or is my best option to use a database and store the id and access it from the database when needed.

Upvotes: 0

Views: 95

Answers (1)

phadaphunk
phadaphunk

Reputation: 13273

Simply enough.

No need for a database. If the only thing that needs to persist is a simple ID, you can save it in a binary file, xml file or plain text.

The best equivalent to session variables I can think of is :

  • Right click on your project
  • Click on properties
  • Click on settings
  • Set you variable there by selecting the type, the name, the scope of the variable (Application or User) and set the value

By the way, the C# type is int

Upvotes: 2

Related Questions