Reputation: 26972
I have a WCF service that will be using basic authentication and would like to be able identify "who" 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.
userName = HttpContext.Current.Request.ServerVariables["LOGON_USER"];
Upvotes: 5
Views: 775
Reputation: 123
OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name
Upvotes: 2
Reputation: 69262
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.
Upvotes: 8