How do you identify authentcated user in WCF?
I have a WCF service that will be using basic authentication and would like to be able identify "w开发者_运维知识库ho" is trying to use the service. I know that the HttpContext.Current is NULL and in the WCF service, but do not know what the alternative is to get the username.
For the website, I can use:
userName = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
How do I get userName in the WCF Service?
Something like this maybe?
string login = OperationContext.Current
.ServiceSecurityContext
.PrimaryIdentity
.Name;
Obviously it helps to check for null reference exceptions along that path but you get the idea.
OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name
精彩评论