Click here to Skip to main content
13,452,396 members (57,784 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked
Posted 16 Sep 2010

Tips & Tricks: Session Management in Silverlight

, 16 Sep 2010
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 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. :( 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.


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


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, 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 Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Book authored:

Connect with me on:

My CodeProject Awards/Prizes:

You may also be interested in...


Comments and Discussions

GeneralMy vote of 3 Pin
Member 697352325-Jan-11 15:15
memberMember 697352325-Jan-11 15:15 
GeneralMy vote of 2 Pin
Dima Pasko26-Sep-10 8:29
memberDima Pasko26-Sep-10 8:29 
GeneralMy vote of 5 Pin
vimarshsharma21-Sep-10 19:49
membervimarshsharma21-Sep-10 19:49 
RantUse With Care!! Pin
InfRes20-Sep-10 22:46
memberInfRes20-Sep-10 22:46 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180318.3 | Last Updated 16 Sep 2010
Article Copyright 2010 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid