WCF UserNamePasswordValidator - access credentials after verification

I use the class UserNamePasswordValidatoras part of security UserNamewith WCF. All this works fine, and the Validateclass function is called and works correctly.

How can I find out what UserNamewas used in my service functions?

For example, let's say if a client connects and requests a list of logs using something like

IList<Log> Logs() { ... }

How can this function know which username was used for this request?

What I want to do is log what UserName calls which function inside the service.

+3
source share
2 answers

Not sure, but you can search

var userName = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
+9
source

, -. :

OperationContext oc = OperationContext.Current;
ServiceSecurityContext ssc = oc.ServiceSecurityContext;
string client = ssc.PrimaryIdentity.Name;
+1

Source: https://habr.com/ru/post/1781682/


All Articles