Get current Windows user name within Silverlight

前端 未结 8 1798
一向
一向 2020-12-02 23:53

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 Interne

8条回答
  •  猫巷女王i
    2020-12-03 00:09

    Unfortunately, I don't think it's possible.

    Although you say that we can assume Windows OS/IE, Silverlight itself certainly doesn't assume this, so most of the normal .NET mechanisms that would ordinarily be available to us to get the current logged on user's name do not exist within the subset of the framework available to Silverlight apps:

    ie.

    System.Net.CredentialCache.DefaultCredentials  
    System.Security.Principal.WindowsIdentity.GetCurrent().Name  
    Environment.UserName  
    

    are all unavailable within a Silverlight application, whereas in (say) a Windows Forms Application, each of these mechanisms is available to use.

    I suppose it makes sense, really, since there's no guarantee that the Silverlight application is going to be running on top of a Windows/IE platform.

    Incidentally, this question was also asked over here:

    Current Windows Username and Domain

    and that thread seems to confirm that there's no native way to achieve this. The thread then goes on to suggest "injecting" the current ASP.NET user name from the ASP.NET page "hosting" the Silverlight app. into the Silverlight application itself prior to it running in the context of the client's machine. Of course, even if this works, it'll only give you the ASP.NET user name from either ASP.NET's forms or windows based authentication and not the Windows username of currently logged on user of the client machine.

提交回复
热议问题