网络上的 C# NamedPipe 在客户端连接时抛出 UnauthorizedAccessException

C# NamedPipe over network throws UnauthorizedAccessException on client connect

我有一个客户端和一个 NamedPipe 服务器。 客户端和服务器 运行 在不同的 Windows 服务上。 在同一台机器上,连接完美无缺。 但是当试图从另一台机器访问服务器时,会抛出 UnauthorizedAccessException 类型的异常(访问被拒绝)。 我研究了几篇文章并在服务器上包含了 AccessRules,但它没有用。 服务器计算机上不存在客户端计算机用户。 这种情况下是否有特定的 / AccessRule 设置? 有人知道解决方案吗?

服务器:

private NamedPipeServerStream _setupServer;

PipeSecurity ps = new PipeSecurity();
//Everyone
ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
//Users
ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
//SYSTEM
ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null), PipeAccessRights.FullControl, AccessControlType.Allow));

using (_setupServer = new NamedPipeServerStream(typeof(ISetupClient).Name, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.None, 4024, 4024, ps))
{
     this._setupServer.WaitForConnection();
     //...
}

客户:

string ipServidor = "192.168.40.155";
using (var setupClient = new NamedPipeClientStream(ipServidor, typeof(ISetupClient).Name, PipeDirection.InOut, PipeOptions.None))
{
    int timeOut = 10;
    setupClient.Connect(timeOut);
    //...
}

我不知道为什么这个问题被否决了 - 我更正了。

我在我的实验室中用不同用户在两台 Win 7 机器上测试了这个。

Windows 中的远程命名管道通过 SMB/CIFS。所以正常的登录限制适用。

如果我在本地安全策略中进行了更改,我能够成功地将此文件发送至 运行:

安全选项

帐户:来宾帐户状态 – 更改为已启用

用户权限分配

拒绝从网络访问此计算机 - 删除 "Guest"

警告

这不是一个好主意。我只是做了更改来验证这一点并立即将它们更改回来。

本地安全策略中还有一个选项用于添加可以匿名访问的命名管道,但这对我来说不起作用。必须对此进行调查。

在我看来,使用命名管道进行未经身份验证的访问并不是最好的解决方案。通常,我更喜欢经过身份验证的连接,但在我的情况下,我的大部分开发都是在企业内部网中进行的,所有计算机都在 Active Directory 环境中,并且有 AD 用户,所以这很容易。

也许您可以使用在两台机器上使用相同用户名和相同密码的老把戏,无需更改上述策略也能奏效。