【问题标题】:How to set PipeSecurity of NamedPipeServerStream in .NET Core如何在 .NET Core 中设置 NamedPipeServerStream 的 PipeSecurity
【发布时间】:2020-05-15 02:51:57
【问题描述】:

我正在将一个库从 .NET Framework 4.6.1 移植到 .NET Standard 2.0。在 Framework 中,NamedPipeServerStream 构造函数可以采用 PipeSecurity 参数,但这不是 Core 中的选项。如何在 Core 中设置NamedPipeServerStream 的安全性?

【问题讨论】:

    标签: .net-core named-pipes .net-standard-2.0


    【解决方案1】:

    显然这是一个已知问题 System.IO.Pipes.AccessControl package does not work #26869。上一篇文章中提到了一种解决方法,建议使用 NamedPipeServerStream.NetFrameworkVersion nuget 包,该包将公开 NamedPipeServerStreamConstructors.New(...),它应该反映所有完整 .NET Framework 构造函数的行为。

    遵循来自 nuget 的 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 2019-12-29
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多