WCF UserNamePasswordValidator - Access credentials after validation
I am using the UserNamePasswordValidator
class as part of the UserName
security with WCF. This all works great and the Validate
function of the class gets called and works properly.
How then can I find out what UserName
was used in my service functions?
For example say if a client connects and requests a list of logs using something like
ILi开发者_Python百科st<Log> Logs() { ... }
How can that function know which UserName was used on that request?
What I want to do is log what UserName calls what function within the service.
Not sure, but you may be looking for
var userName = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
I believe there is something in the operation context. Try this:
OperationContext oc = OperationContext.Current;
ServiceSecurityContext ssc = oc.ServiceSecurityContext;
string client = ssc.PrimaryIdentity.Name;
精彩评论