Microsoft Silverlight – Accessing Session Objects

You must use a web service or wcf service to access the silverlight applications host website application and session objects.

The host website needs a web service with the following code.

<WebMethod(EnableSession:=True)> _
Public Sub SetText(ByVal value As String)
   Session("Text") = value
End Sub
 
<WebMethod(EnableSession:=True)> _
Public Function GetText() As String
   Return Session("Text")
End Function

The silverlight application uses this code:

Dim ws As New ServiceReference1.webservice1SoapClient
ws.SetTextAsync(Me.txtTextBox.Text)

In the aspx page, you can reference the Session Object using this code:

Me.TextBox1.Text = service1.GetText()

The above code is placing the value into a textbox on the aspx server page.
In order to transfer control to the aspx page from silverlight, use the following code:

Dim Address As String = ""
Dim add1 As String = App.Current.Host.Source.OriginalString
Dim parts() As String
parts = Split(add1, "/")
 
Dim total As Integer = 0
total = parts.Length
total = total - 2
Dim add2 As String = ""
 
Dim counter As Integer = 0
 
For counter = 0 To total - 1
add2 += parts(counter) & "/"
Next
 
add2 += "default.aspx"
 
HtmlPage.Window.Navigate(New Uri(add2), "_blank")

Leave a Reply