Thread.CurrentPrincipal.Identity.Name是空的WPF [英] Thread.CurrentPrincipal.Identity.Name is empty from WPF

查看:337
本文介绍了Thread.CurrentPrincipal.Identity.Name是空的WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改

最简单的问题是,我怎么能得到 Thread.CurrentPrincipal.Identity.Name 让当前用户登录在WPF?

The simple question is, how can I get Thread.CurrentPrincipal.Identity.Name to have the current user logon in WPF?

END修改

我试图调用一个现有的方法(而不是在任何类型的服务;只是在一个POCO的方法)与获取当前用户:

I'm trying to call an existing method (not in any sort of service; just a method in a POCO) that retrieves the current user with:

Thread.CurrentPrincipal.Identity.Name

此代码是别人写的,和(大概)的作品与他的ASP .NET MVC项目。我想打电话给从WPF同样的方法,和名称现在是空白的。

This code was written by someone else, and (presumably) works with his ASP.NET MVC project. I'm trying to call this same method from WPF, and Name is now blank.

有什么我可以做这件事?

Is there anything I can do about this?

推荐答案

设置 Thread.CurrentPrincipal中新WindowsPrincipal(WindowsIdentity.GetCurrent()) 。然后,您将有可靠该线程的生命周期的现任校长。你必须重复这个你旋转起来,并且其他线程

Set Thread.CurrentPrincipal to new WindowsPrincipal(WindowsIdentity.GetCurrent()). You'll then reliably have the current principal for the lifetime of that thread. You'll have to repeat this on any other threads you spin up.

编辑:我还要提及的 SetThreadPrincipal 和的 SetPrincipalPolicy 上的AppDomain方法。这应该在应用程序启动完成,并且创造了新的线程现在将默认看到这个主体。如果此方法不叫,每一个新的线程会先有自己的GenericPrincipal一次。

I should also mention the SetThreadPrincipal and SetPrincipalPolicy methods on AppDomain. This should be done on application startup, and new threads created will now see this principal by default. If this method isn't called, every new thread will start out with GenericPrincipal again.

这篇关于Thread.CurrentPrincipal.Identity.Name是空的WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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