我有一个客户端和一个 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);
//...
}