【问题标题】:Get WindowsAccount for current user that made the request to the WCF service获取向 WCF 服务发出请求的当前用户的 WindowsAccount
【发布时间】:2011-10-07 12:29:40
【问题描述】:

嗨,

我有一个同时使用 WindowsAuthentication 和常规用户名/密码身份验证的 WCF 服务(会话)。

现在我需要获取客户端上已将请求发送到 WCF 服务的当前用户。

我知道这可以在 IAuthorizationPolicy 中完成,但我不确定如何在 webmethod 中执行此操作?

我试过了:

WindowsIdentity.GetCurrent();

然而,这确实只返回运行 WCF 服务的当前用户(似乎),而不是已经满足当前请求的客户端用户?

请多指教

致以最诚挚的问候

【问题讨论】:

    标签: .net wcf authentication


    【解决方案1】:

    ServiceSecurityContext.Current.WindowsIdentity 应该可以解决问题。

    【讨论】:

      【解决方案2】:

      发送请求的用户的身份可通过 AuthorizationContext 在 WCF 中获得,

      AuthorizationContext 上下文 = ServiceSecurityContext.Current.AuthorizationContext

      这适用于任何类型的身份验证方法,无论您使用的是 windows 还是用户名/密码。

      默认情况下,WCF 不会在正在运行的线程中设置标识,因此您应该无法使用 WindowsIdentity 获取它。

      问候 巴勃罗。

      【讨论】:

        猜你喜欢
        • 2016-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多