我有一个将使用基本身份验证的WCF服务,希望能够识别“谁”正在尝试使用该服务。我知道httpContext.current为空,在wcf服务中,但不知道获取用户名的备选方案是什么。
userName = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
也许是这样?
string login = OperationContext.Current .ServiceSecurityContext .PrimaryIdentity .Name;
显然,沿着该路径检查空引用异常有助于您的理解。
operationContext.current.serviceSecurityContext.primaryIdentity.name