Get WindowsAccount for current user that made the request to the WCF service
Hi,
I got a WCF service(session) that uses both WindowsAuthentication and regular UserName/Password authentication.
Now I need to get the current user on the client开发者_运维技巧 that have sent the request to the WCF service.
I know that this can be done in IAuthorizationPolicy but Im not sure how to do this in a webmethod?
I have tried this :
WindowsIdentity.GetCurrent();
This does however only return the current user that runs the WCF service(it seems), not the client user that have med the current requst?
Pleas advice
BestRegards
ServiceSecurityContext.Current.WindowsIdentity
should do the trick.
The identity of the user that sent the request is avaialable in WCF through the AuthorizationContext,
AuthorizationContext context = ServiceSecurityContext.Current.AuthorizationContext
That works for any kind of authentication method, no matter if you use windows or username/password.
WCF by default does not set the identity in the running thread so you shouldn't able to get it with WindowsIdentity.
Regards Pablo.
精彩评论