frosty

How to retrieve a machine name in a Silverlight Application

Rate this Entry
Silverlight itself does not provide a way to do this. However, since Silverlight is hosted in Asp.Net, we can use InitParams to get the host name.

First whatever your asp.net landing page is, add a public property called HostName.

In the Page_Load event, we assign a value to HostName.

Code:
 
public string HostName { get; set; }         
 
protected void Page_Load(object sender, EventArgs e)        
{            
            HostName = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;        
}
In the default.aspx code, add the following to the initParms:

Code:
 
<param name="initParams" value="<%= string.Format("HostName={0}", HostName) %>" />
Finally, in the App.Xaml.cs, Application_Startup() event, add the following code.

Code:
 
string _hostName = e.InitParams["HostName"];
You should have the FQDN of the host machine running the silverlight app.
Categories
.Net , ‎ UI , ‎ Silverlight

Comments