how to handle Session In SilverLight
How can开发者_JAVA技巧 we store user information in session in silverlight, mean how to handle it ?
As mentioned, Silverlight maintains application state, unlike a traditional ASP.NET application where each Request is semi-autonomous. In the latter case, you can use the Session to maintain some state information between those Requests.
In Silverlight, you can authenticate the user by means of a service call to the server, after which you can just use normal OO design to craft yourself an AuthenticatedUser or CurrentUser class, or something along those lines, to hold this information.
If you're asking how to persist or retrieve information from your db or membership store, you obviously need to go through web services to communicate with your backend.
It's also possible to send data down silverlight via the startup keys:
In Silverlight Application.Startup (app.axml.vb):
For Each Key In e.InitParams.Keys
If Key.ToLower() = "userid" Then
Page.UserId = e.InitParams(Key)
End If
Next
In your page:
Xaml1.InitParameters = "UserId=1050"
Page.UserId is a public variable in my page.axml.vb, but you can build a string to pass session info from the server into silverlight without invoking a WS.
精彩评论