来自WCF请求的IPrincipal

Tam*_*mir 4 .net c# security wcf wcf-security

我可以在获取WCF服务时获取请求者窗口IPrincipal吗?

mar*_*c_s 5

使用此代码,您可以检查WCF服务中的当前安全上下文.

如果用户已通过身份验证,并且WindowsPrincipal不为null,那么您使用的是Windows安全模型 - 您可以访问所有相关信息:

ServiceSecurityContext current = ServiceSecurityContext.Current;

if (!current.IsAnonymous && current.WindowsIdentity != null)
{
    string userName = current.WindowsIdentity.Name;
}
Run Code Online (Sandbox Code Playgroud)