Using Session in Silverlight


Silverlight did not support session as in asp.net. So we have to create a class for that.
Here I am creating property called  System.Collections.Generic.Dictionary.
This allows representing a collection of keys and values.

Now we create a class called sessionmanager and defining Dictionary property here.
public class SessionManager
{
private static Dictionary<string, object> session = new Dictionary<string, object>();
public static Dictionary<string, object> Session
{
get { return SessionManager.session; }
set { SessionManager.session = value; }
}
}

Then in your code behind page,

Pass the value as,
SessionManager.Session["userid"] = “your value goes here”;
And retrieve the value as
String sString = SessionManager.Session["userid"].ToString();

No comments:

Post a Comment