Keep Session Alive in Silverlight (Maintaing Session in Silvelright)

In one of my previous post, I have explained on how to add / interact with session values in Silverlight. (http://devqueries.webs.com/apps/blog/show/5394971-maintaining-session-in-silverlight) But many of you might need to keep that session alive.

What happens to Session in Silverlight?
Since, Silverlight application is embedded in an aspx page, and no further web requests are processed within the silverlight application, session will time out after the given period of time. To overcome this, do the following:

1. Add a webpage (e.g. SessionAlive.aspx) in the web project
2. Call this web page from the Silverlight application using the web client method.
a. Calls can be either using a timer or in the OnNavigating part of the Silverlight Page

e.g:

var client = new WebClient();
client.DownloadStringAsync(new Uri("../SessionAlive.aspx", UriKind.Relative));

This will keep the session alive in your silverlight application

Comments