Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tips & Tricks: Session Management in Silverlight

, 16 Sep 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Session Management in Silverlight

In various forums (mainly in Silverlight.Net Forum), I have seen people asking a question: “How to implement Session Management in Silverlight?” The simple answer is: “Session Management is not available in Silverlight”. Why? If it is not there, how can we implement it?

Ok, If you are new to Silverlight, you need to know about this. Hence, in this post, I will describe Silverlight Session Management. The targeted audience for this post is mainly the beginners of Silverlight. Read it and if you have any queries, let me know.
As you all know that once you visit the Silverlight site, it first downloads the .XAP file to the client’s PC and then runs from there. Other side, the session is a server side concept. It maintains in the server. Hence, your Silverlight application can’t maintain the session. Sad smile So, what to do?

You can easily maintain an application level static variable in the client side and store your data. Whenever you need, you can access from various Silverlight pages across your application.

Here I will show how to do this. Create a static class called “SessionManager”. Now create a Dictionary Property of type <string, object> and name it as “Session”.

Now from your application, whenever you want to set a value to that object, use the SessionManager class to set the key/value pair to the Session property.

When you want to access the same key/value, get it from the SessionManager.Session property. Have a look into the code:

That’s it. Now you are able to store values like you do in ASP.NET Session. But be sure that it is application level and hence if you refresh the browser, you will lose all your records.


License

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

Share

About the Author

_ Kunal Chowdhury _
Technical Lead
India India
Kunal Chowdhury is a Microsoft "Client Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik MVP, Nokia Developer Champion, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.
 
He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows 8 (WinRT). He posts his findings, articles in his technical blog and CodeProject.
 
Technical Blog: http://www.kunal-chowdhury.com
Facebook: http://facebook.com/blog.kunal
Twitter : http://twitter.com/kunal2383
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 Pinmembervimarshsharma21-Sep-10 20:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411022.1 | Last Updated 16 Sep 2010
Article Copyright 2010 by _ Kunal Chowdhury _
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid