获取登录用户 [英] Get Logged In User

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

问题描述

我们公司正在完成我公司的大型应用程序.它利用WCF作为Active Directory的骨干进行身份验证.这对于两个站点之一非常适用,因为身份验证模型是Windows,并且您必须是域的一部分才能登录该站点.我所提出的问题与可以从外部访问的其他站点有关.它将为代理调用设置ClientCredentials.Windows.ClientCredential,并使用特定用户/通行证来模拟AD用户,以便使用完整的安全模型.这一切也完全符合预期.

My company has a large application we are finishing up. It utilizes WCF as the back-bone with Active Directory for authentication. This works perfectly for one of the two sites as the authentication model is Windows and you have to be part of the domain to sign into the site. The question I have relates to the other site which is externally accessible. It sets ClientCredentials.Windows.ClientCredential for the proxy call with a specific user/pass for impersonation of an AD-user so the full security model works. This all works exactly as expected too.

我的问题是,在网络上我可以使用HttpContext.Current.User.Identity.Name从Forms身份验证项中获取当前登录的用户,但是要做到这一点,我必须确保System.Web存在针对我当前正在使用的DLL的引用.我们的基础对象来自一个不了解System.Web的简单类.有没有办法找出在该基础对象项目中登录的Forms用户?我尝试了System.Security.Principal,但这只能使我凭所能知道的方式访问Windows帐户,对我无济于事.

The question I have is, on the web I can use HttpContext.Current.User.Identity.Name to get the currently logged in user from the Forms authentication piece, but to do this I have to make sure a System.Web reference exists against the DLL I'm currently working in. Our base objects come from a simplistic class that doesn't know about System.Web. Is there a way to find out the Forms user who is logged in inside that base object project? I tried System.Security.Principal but that only gives me access to the Windows accounts from what I could tell and won't do me any good.

我知道一种选择是仅引用System.Web并完成它,但这对我来说确实是个难题,而不是最好的选择,所以我希望在这里提供一些提示.

I know an option is to just reference System.Web and be done with it but that sounds really klugy to me and not the best option so I'm hoping for some tips here.

推荐答案

Thread.CurrentPrincipal.Identity将执行与HttpContext.CurrentContext...

它将返回与当前执行线程关联的身份,在大多数情况下,该身份是登录的用户*.

It will return the identity associated with the current executing thread, which in most cases, is the logged on user*.

注意:*如果您使用委派/模拟或作为服务帐户运行,它将返回该线程所使用的身份的帐户,但是在您的情况下,听起来好像您在执行任何上下文操作身份切换.

Note: *If you are using delegation/impersonation or running as a service account, it will return the account of which ever identity the thread is under, but in your case, it doesn't sound like you are doing any context identity switching.

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

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