I am working with a Silverlight business application that is using Windows Authentication.
When a user is signed into the machine, and access the Silverlight URL, the data they are presented with is based on their Windows sign in details. The user name is retrieved from the login status on the page like so-
string fullUserName = WebContext.Current.User.DisplayName;
string userName = fullUserName.Substring(fullUserName.IndexOf('\\') + 1);
So for instance the fullUserName
here would be 'machineName\UserName' and then the second line gets rid of 'machineName\' to just leave the user name.
One the user name has been extracted from the page, it is used in a webservice call to bring back data based on that user account-
void OnLoad(object sender, RoutedEventArgs e)
{
string fullUserName = WebContext.Current.User.DisplayName;
string userName = fullUserName.Substring(fullUserName.IndexOf('\\') + 1);
WebService.Service1SoapClient client = new WebService.Service1SoapClient();
client.IDReturnCompleted += new EventHandler<IDReturnCompletedEventArgs>(client_IDReturnCompleted);
client.IDReturnAsync(userName);
}
This works fine on all pages of the Silverlight apart from the home page, which is the first page when loaded. I believe this is due to the fact that the callbacks are asynchronous and therefore the value user name has not been initialised yet. But by the time a user has clicked on a new link, the value has loaded.
Is it possible to get this value in the Home page? I have tried it in both the load event and InitializeComponent on the home page but the value is not back from the web service yet.