在Silverlight中获取当前的Windows用户名 [英] Get current Windows user name within Silverlight

查看:61
本文介绍了在Silverlight中获取当前的Windows用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Silverlight获取当前登录的用户名?您可以假定用户具有Windows操作系统,并且Silverlight应用程序托管在Internet Explorer中.不能选择使用ASP.NET从服务器端获取身份,此Silverlight应用程序将托管在静态HTML文件中.

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.

推荐答案

不幸的是,我认为这是不可能的.

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

尽管您说我们可以假定使用Windows OS/IE,但是Silverlight本身当然不假定这样做,因此通常不提供给我们的用于获取当前登录用户名的大多数常规.NET机制都不存在.在Silverlight应用程序可用的框架子集中:

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:

即.

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

在Silverlight应用程序中都不可用,而在(例如)Windows Forms应用程序中,可以使用这些机制中的每一种.

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

我想这确实是有道理的,因为不能保证Silverlight应用程序将在Windows/IE平台上运行.

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:

当前的Windows用户名和域

,并且该线程似乎确认没有本地方法可以实现此目的.然后,该线程继续建议从托管" Silverlight应用程序的ASP.NET页面注入"当前的ASP.NET用户名.在客户端计算机的上下文中运行之前,请先将其导入Silverlight应用程序本身.当然,即使这可行,它也只会从ASP.NET的表单或基于Windows的身份验证中为您提供ASP.NET用户名,而不是当前登录的客户端用户的Windows用户名机器.

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.

这篇关于在Silverlight中获取当前的Windows用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆