Within our Silverlight application if we want to know the URI where our Silverlight content is running, we can tap into System.Windows.Browser namespace. This namespace contains object which are full of Browser related information. This is an example of retrieving the URI from within Silverlight application.

<StackPanel x:Name="LayoutRoot" Margin="10">
  <TextBlock Text="Your URL is: " />
  <TextBlock Text="{Binding AbsoluteUri}" />
</StackPanel>

 

In our C# code we can set the DataContext so that the second TextBlock above displays the information we desire.

private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
  LayoutRoot.DataContext =
    System.Windows.Browser.HtmlPage.Document.DocumentUri;
}

 

Here is my output which displays the URL at which my Silverlight plugin is hosted.

image

Tagged with:
 

One Response to Get URI Of Silverlight Plugin Host Page

  1. JR says:

    This was very handy.
    One issue I am having is the URL changes depending on whether I am local or deployed to IIS:

    http://localhost/SilverlightRestExampleTestPage.aspx“;
    http://localhost//SilverlightRestExampleTestPage.aspx“;

    I am trying to parse these so my Silverlight client can post back to the server it came from.

    Know of an elegant way to just get the:

    So I can dynamically build my URL on the client?

    Thx, JR

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>