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?
Net 6.0 has introduced NamedPipeServerStreamAcl Class.
You can use the Create method to create the stream with PipeSecurity...
using System.IO.Pipes;
using System.Security.AccessControl;
using System.Security.Principal;
if (!System.OperatingSystem.IsWindows())
throw new PlatformNotSupportedException("Windows only");
SecurityIdentifier securityIdentifier = new SecurityIdentifier(
WellKnownSidType.AuthenticatedUserSid, null);
PipeSecurity pipeSecurity = new PipeSecurity();
pipeSecurity.AddAccessRule(new PipeAccessRule(securityIdentifier,
PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance,
AccessControlType.Allow));
NamedPipeServerStream stream = NamedPipeServerStreamAcl.Create(
"SecurityTestPipe", PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 0, 0, pipeSecurity);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With