代码之家  ›  专栏  ›  技术社区  ›  RSolberg

您如何在WCF中标识授权用户?

  •  5
  • RSolberg  · 技术社区  · 14 年前

    我有一个将使用基本身份验证的WCF服务,希望能够识别“谁”正在尝试使用该服务。我知道httpContext.current为空,在wcf服务中,但不知道获取用户名的备选方案是什么。

    对于网站,我可以使用:

    userName = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
    

    如何在WCF服务中获取用户名?

    2 回复  |  直到 14 年前
        1
  •  8
  •   Josh    14 年前

    也许是这样?

    string login = OperationContext.Current
                                   .ServiceSecurityContext
                                   .PrimaryIdentity
                                   .Name;
    

    显然,沿着该路径检查空引用异常有助于您的理解。

        2
  •  2
  •   Perplexed    14 年前

    operationContext.current.serviceSecurityContext.primaryIdentity.name