问题
I'm porting a library from .NET Framework 4.6.1 to .NET Standard 2.0. In Framework, the NamedPipeServerStream
constructor could take a PipeSecurity
parameter, but that isn't an option in Core. How do you set the security of a NamedPipeServerStream
in Core?
回答1:
Apparently it's a known issue
System.IO.Pipes.AccessControl package does not work #26869. There's a workaround mentioned in the last post suggesting usage of NamedPipeServerStream.NetFrameworkVersion nuget package which will expose NamedPipeServerStreamConstructors.New(...)
which should mirror behavior of all the full .NET Framework constructors.
Follows a code sample from the nuget's github
using System.IO.Pipes;
var pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null), PipeAccessRights.ReadWrite, AccessControlType.Allow));
using var serverStream = NamedPipeServerStreamConstructors.New(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, 0, 0, pipeSecurity);
来源:https://stackoverflow.com/questions/59969943/how-to-set-pipesecurity-of-namedpipeserverstream-in-net-core