Get current Windows user name within Silverlight

huseyint picture huseyint · Jul 24, 2009 · Viewed 40.2k times · Source

Is it possible to get the currently logged in user's username with Silverlight? You can assume that user has Windows OS and the Silverlight application is hosted in Internet Explorer. Getting the identity from server side with ASP.NET is not an option, this Silverlight application will be hosted on a static HTML file.

Answer

Richard picture Richard · Dec 3, 2009

You can manage to get by this way.

1) Create asp.net web service application.

2) Implement web service and method to call from silverlight applicaton.

[WebMethod]
public string GetClientUserName()
{
    return System.Web.HttpContext.Current.User.Identity.Name.ToString();
}

3) Deploy this web service application on web server. Don't allow anonymous user to access this.

4) Add this service to Silverlight application. (Add service reference)

5) Now, you can call this method and get user name from entire silverlight application.