开发者

Get WindowsAccount for current user that made the request to the WCF service

开发者 https://www.devze.com 2023-04-11 05:07 出处:网络
Hi, I got a WCF service(session) that uses both WindowsAuthentication and regular UserName/Password authentication.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号