How to access HttpContext.Current.User.Username in WCF service

后端 未结 2 590
不知归路
不知归路 2020-12-17 10:06

How can I access HttpContext.Current.User.Username from a web application in a WCF service?

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 10:44

    Generally you don't - HttpContext is an ASP.NET concept and doesn't apply to WCF unless you run it with ASP.NET Compatibility turned on.

    If you want the current user in WCF then use ServiceSecurityContext.Current.PrimaryIdentity or get the security context via the OperationContext.

提交回复
热议问题