Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
is there any way using session like asp net in wpf. AND is it good when make session class , using singleton design pattern. is it sense?

i need this becouse;
when user log in i have to know user id in every window
Posted
Updated 26-May-15 6:08am
v5

No.
Why would you need some method of preserving data across a session on a permanently hosted application?

The Session is there to preserve information specific to a client, without having to save the page and all it's context. It's needed because once the page HTML has been sent to the browser, the application can be closed, and the Session preserves information which may be needed on a post back. That isn't the case with a WPF app - it and it's full context remains "live" until the application is closed - and it doesn't have post backs!
 
Share this answer
 
Sessions in Web applications store the client side state (lots of clients), in a WPF application you only have 1 client.

Yes, you can create a "session" object to store data in [a database is the same thing].

Depending on what you want to do it may be a singleton.
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 24-May-15 10:59am    
A session is not equivalent to database in any way. If you store something in database, it remains there until you remove it... Where as in session things are removed if you close the app. You can say, cookies are equivalent to database.
Mehdi Gholam 24-May-15 13:19pm    
Sessions can be persisted, databases can be in memory.
Afzaal Ahmad Zeeshan 24-May-15 13:26pm    
No, sessions are in memory (they are removed when the app starts again or when user visits the web page again) and database is stored in file system. They are written on the hard drive. There is a lot of difference in them. As I said, you can say cookies are similar to database. They are both stored physically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900