Banshee
Banshee

Reputation: 15837

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

Upvotes: 1

Views: 1186

Answers (2)

Pablo Cibraro
Pablo Cibraro

Reputation: 3959

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.

Upvotes: 2

Christian Hayter
Christian Hayter

Reputation: 31071

ServiceSecurityContext.Current.WindowsIdentity should do the trick.

Upvotes: 1

Related Questions