开发者

How do you identify authentcated user in WCF?

开发者 https://www.devze.com 2022-12-30 18:15 出处:网络
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

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

0

精彩评论

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

关注公众号