Handling Sessions in Silverlight

In this article, we are going to see ‘How to handle Sessions in Silverlight’.

Implementing Session Management:

Session is server side concept whereas the Silverlight page, first downloads the XAP file to the client’s PC and then runs from there. Hence, your Silverlight application can’t maintain the session. So, What to do?
You can easily maintain a application level static variable in the client side and store your data. Whenever you need, you can access from various Silverlight page 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 as like below:

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 loose all your records.

Leave a Reply

Your email address will not be published. Required fields are marked *