WCF UserNamePasswordValidator – validation后访问凭据
我使用UserNamePasswordValidator
类作为WCF的UserName
安全性的一部分。 这一切都很好,类的Validate
函数被调用并正常工作。
那么如何才能找到我的服务function中使用的UserName
?
例如,假设客户端使用类似的东西连接并请求日志列表
IList Logs() { ... }
该函数如何知道该请求使用了哪个UserName?
我想要做的是记录UserName调用服务中的哪个函数。
不确定,但你可能正在寻找
var userName = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
我相信在运营环境中有一些东西。 试试这个:
OperationContext oc = OperationContext.Current; ServiceSecurityContext ssc = oc.ServiceSecurityContext; string client = ssc.PrimaryIdentity.Name;