Silverlight 4 Get current user

I saw this question regarding Silverlight 2, but I did not see any questions about Silverlight 4.

Is there a way to get the current user to run the application in Silverlight 4.0? It seemed to me that I remember that this is one of the features of 4.0, but I can not find it. (Maybe it was just wishful thinking on my part.) I would suggest that this should come from the OS that launches the browser or the browser itself. (The application is not installed locally, it is running in a browser)

I have a solution in which I call a web service method that simply does the following to get the username. However, I would not want you to call the web service

HttpContext.Current.User.Identity.Name.ToUpper(); 

Thanks in advance!

+4
source share
5 answers

It may be easier for you to simply pass the name to the silverlight application as a parameter

+1
source

Obtaining a client-side username in a standard Silverlight Silverlight application simply does not happen, it would be very dangerous if it were possible.

Personally, if I had this requirement, I would probably use some web services, WCF, or the simple server side of IHttpHandler . However, I would be inclined to call it something like "UserContext" and send XML. XML will contain the username. This will add additional user state to XML later when new requirements become clear. Adding these new pieces of information would be easy.

+2
source

In the Silverlight object tag, add a new parameter named as initParam (note the case). Thanks to this, you can transfer values ​​in the form of keys = value [, key = value, ...]. Here I pass the usrIdentity key and value as the name of the current user ID.

 <param name="initParams" value=' usrIdentity=@HttpContext.Current.User.Identity.Name '/> 

In your App.xaml.cs in Application_StartUp you will have the following code

 private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new MainPage(); if (e.InitParams.ContainsKey("usrIdentity")) { //I have a public static string WindowsUser on my MainPage.xaml.cs MainPage.WindowsUser = e.InitParams["usrIdentity"]; } } 

This is from a hewstone suggestion. MS Link http://msdn.microsoft.com/en-us/library/cc189004 (v = vs .95) .aspx

+1
source

I searched the same thing, but as far as I found, this is still not possible.

Someone posted an ASP.Net workaround here Get the current Windows username in Silverlight , but I still haven't had the opportunity to try it

0
source

Correction to @Vishnoo Rath; you should try the following:

 <param name="initParams" value="usrIdentity=<%=HttpContext.Current.User.Identity.Name%>"/> 
0
source

All Articles