Description
The provided example does not compile / work. It says to do the following:
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenNamedPipe("MyPipeName", listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
// Configure PipeSecurity
listenOptions.UseNamedPipes(options =>
{
var pipeSecurity = new PipeSecurity();
// Grant read/write access to the Users group
pipeSecurity.AddAccessRule(new PipeAccessRule(
"Users",
PipeAccessRights.ReadWrite,
AccessControlType.Allow));
// Add additional rules as needed
options.PipeSecurity = pipeSecurity;
});
});
});
However there are three issues I had:
- You cannot call
UseNamedPipes on listenOptions. This call needs to be made on the WebHost builder like this:
var builder = WebApplication.CreateBuilder(args);
// Configure PipeSecurity
builder.WebHost.UseNamedPipes(options =>
{
var pipeSecurity = new PipeSecurity();
// Grant read/write access to the Users group
pipeSecurity.AddAccessRule(new PipeAccessRule(
"Users",
PipeAccessRights.ReadWrite,
AccessControlType.Allow));
// Add additional rules as needed
options.PipeSecurity = pipeSecurity;
});
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenNamedPipe("MyPipeName", listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
});
- Starting the server failed because it says the named pipe is already in use. This is actually misleading because it was caused by access being denied. I believe you need to also grant
CreateNewInstance permission to the current user otherwise it is not allowed to create the named pipe.
pipeSecurity.AddAccessRule(new PipeAccessRule(
"Users",
PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance,
AccessControlType.Allow));
- Setting
PipeSecurity requires CurrentUserOnly to be set to false, otherwise you get an ArgumentException:
System.ArgumentException: 'pipeSecurity' must be null when 'options' contains 'PipeOptions.CurrentUserOnly'. (Parameter 'pipeSecurity')
This may also be the reason why you need to grant CreateNewInstance rights, otherwise the current user has no permissions to do so.
The example should probably look like this (excluding usings, etc.):
var builder = WebApplication.CreateBuilder(args);
// Configure PipeSecurity
builder.WebHost.UseNamedPipes(options =>
{
var pipeSecurity = new PipeSecurity();
// Grant read/write access to the Users group
pipeSecurity.AddAccessRule(new PipeAccessRule(
"Users",
PipeAccessRights.ReadWrite | PipeAccessRights.CreateNewInstance,
AccessControlType.Allow));
// Add additional rules as needed
options.PipeSecurity = pipeSecurity;
options.CurrentUserOnly = false;
});
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenNamedPipe("MyPipeName", listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
});
Page URL
https://learn.microsoft.com/en-us/aspnet/core/grpc/interprocess-namedpipes?view=aspnetcore-10.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/grpc/interprocess-namedpipes.md
Document ID
58d486b8-0e04-9767-2089-deb43a28f56b
Platform Id
a2d799be-3207-916a-b50a-6cc65840d5b9
Article author
@JamesNK
Metadata
- ID: 58d486b8-0e04-9767-2089-deb43a28f56b
- PlatformId: a2d799be-3207-916a-b50a-6cc65840d5b9
- Service: aspnet-core
- Sub-service: grpc
Related Issues
Description
The provided example does not compile / work. It says to do the following:
However there are three issues I had:
UseNamedPipesonlistenOptions. This call needs to be made on theWebHostbuilder like this:CreateNewInstancepermission to the current user otherwise it is not allowed to create the named pipe.PipeSecurityrequiresCurrentUserOnlyto be set tofalse, otherwise you get anArgumentException:System.ArgumentException: 'pipeSecurity' must be null when 'options' contains 'PipeOptions.CurrentUserOnly'. (Parameter 'pipeSecurity')This may also be the reason why you need to grant
CreateNewInstancerights, otherwise the current user has no permissions to do so.The example should probably look like this (excluding usings, etc.):
Page URL
https://learn.microsoft.com/en-us/aspnet/core/grpc/interprocess-namedpipes?view=aspnetcore-10.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/grpc/interprocess-namedpipes.md
Document ID
58d486b8-0e04-9767-2089-deb43a28f56b
Platform Id
a2d799be-3207-916a-b50a-6cc65840d5b9
Article author
@JamesNK
Metadata
Related Issues