WCF 服务 - 自定义主体 [英] WCF Service - Custom Principal
问题描述
在我的 WCF 服务类的构造函数中,我将当前主体设置为消息头中传递的主体:
In the constructor of my WCF service class I am setting the current principal to be that of the principal passed in the header of the message:
Thread.CurrentPrincipal = OperationContext.Current.IncomingMessageHeaders.GetHeader<BBPrincipal>("bbPrincipal", "ns");
这似乎工作正常,但是当我在方法中引用主体时,Thread.CurrentPrincipal 已恢复为 WindowsPrincipal.
This seems to work fine, however when I come to reference the principal in a method, the Thread.CurrentPrincipal has reverted to a WindowsPrincipal.
推测该方法是在不同的线程上触发的.如何确保该方法使用的是服务构造函数中的主体集?
Presumably the method is firing on a different thread. How can I ensure that the method is using the principal set in the constructor of the service?
推荐答案
我刚刚找到了最初问题的答案.为了阻止 WCF 用空白覆盖主体,请在行为配置中设置以下内容:
I've just found the answer to my original question. In order to stop WCF overriding the principal with a blank one, set the following in the behavior configuration:
<serviceAuthorization principalPermissionMode="None" />
就这么简单,无需对现有代码库进行彻底更改.
Simple as that and no need to made sweeping changes to the existing code base.
这篇关于WCF 服务 - 自定义主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!