【发布时间】:2011-12-02 07:54:42
【问题描述】:
我有一个使用模拟的 WCF 服务。我已通过我添加到我的服务中以进行调试的以下方法验证了正在使用正确的身份。
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public AuthUser GetUser()
{
AuthUser user = new AuthUser();
user.UserName = WindowsIdentity.GetCurrent().Name;
return user;
}
没有指定 [OperationBehavior] 我收到NT AUTHORITY\NETWORK SERVICE,正如我所期望的那样。使用该属性,我看到用户返回了我期望的DOMAIN\DOMAINUSER。
该服务目前仍在返回一个错误,它无权执行以下行中的文件操作:
FileStream fs = new FileStream(filename, FileMode.Create,FileAccess.Write);
我已通过检查 Active Directory 组和成员身份验证该目录对域用户具有完全访问权限。
我在服务的 web.config 中定义了<identity impersonate="true" />,并在客户端代码中定义了这个:
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation
如果相关,这是我的服务端绑定:
<wsHttpBinding>
<binding name="default" maxReceivedMessageSize="200000">
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
</binding>
</wsHttpBinding>
在 IIS 中启用匿名访问,因为我让 WCF 处理身份验证。
【问题讨论】:
-
不是很清楚,但是你在服务方法中创建 FileStream 对吗?
-
是的。具体来说,它位于一个私有方法中,由 [OperationContract] 定义的方法调用。
-
该文件是否在运行 WCF 服务的同一台机器上,或者您是否尝试访问网络共享上的文件?
-
文件位于使用 UNC 路径的网络共享上。
标签: c# wcf impersonation delegation