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

查看:17
本文介绍了在 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 操作系统/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 窗体应用程序中,这些机制中的每一种都可以使用.

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天全站免登陆