views:

38

answers:

2

How can we store user information in session in silverlight, mean how to handle it ?

A: 

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.

Bobby
A: 

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.

Ged
That is not a great idea - someone could easily compromise this mechanism by editing the InitParameters included in the object tag/html, setting the value to whatever user they like, gaining that other user's access. The only reliable way to authenticate is through a secure channel, like an SSL-encrypted web service call.
Bobby