Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 针对服务器端WCF调用方的ActiveDirectory组进行验证_C#_Wcf_Client Server_Nettcpbinding_Windows Identity - Fatal编程技术网

C# 针对服务器端WCF调用方的ActiveDirectory组进行验证

C# 针对服务器端WCF调用方的ActiveDirectory组进行验证,c#,wcf,client-server,nettcpbinding,windows-identity,C#,Wcf,Client Server,Nettcpbinding,Windows Identity,我有一个WCF服务,托管在WindowsService中,使用nettcpbinding,如果发送者属于特定的广告组,我想在其中执行C代码检查 可能吗?如果是这样,怎么做?假设WCF客户端和服务器位于同一个域上,您可以这样做: 在客户端,您允许使用windows标识对客户端进行身份验证: using System.Security.Principal; .... ServiceReference.ServiceClient client = new ServiceReference.Servic

我有一个WCF服务,托管在WindowsService中,使用nettcpbinding,如果发送者属于特定的广告组,我想在其中执行C代码检查


可能吗?如果是这样,怎么做?

假设WCF客户端和服务器位于同一个域上,您可以这样做:

在客户端,您允许使用windows标识对客户端进行身份验证:

using System.Security.Principal;
....
ServiceReference.ServiceClient client = new ServiceReference.ServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Identification;
在服务器端,您可以检索呼叫者windows标识并测试它是否属于以下组:

    WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
    WindowsPrincipal windowsPrincipal = new WindowsPrincipal(callerWindowsIdentity);
    var isInRole = windowsPrincipal.IsInRole("Users");

这是可能的,但实现取决于应用程序拓扑(例如,服务如何承载:IIS、Windows服务、控制台应用程序e.t.c.,客户端是否在同一网络/域中访问服务,Windows身份验证Kerberos或NTLM e.t.c。)。@lonut Ungureanu-WindowsService(更新了问题)