Hejle
MinimalApi vs Mvc - ValidationOfHeaders
I have been playing around with MinimalApi, and was surprised to see that MinimalApi could not handle validating Required HttpHeaders in the same way that MvcControllers can:
MinimalApi Code
Mvc Code
The Mvc Examples returns a ValidationProblemDetails-based error if TraceId while MinimalApi just retuns 400.
Does anyone know, how I can get MinimalApi to validate headers and send a meaningful error back (hopefully a ValidationProblemDetails).
7 replies
Docker - NanoServer - Dotnet with PowershellCore
I have created a DockerFile with Dotnet running in NanoServer, and got a bit annoyed at the CMD in there.
So I have spent hours trying to add PowerShellCore to it.
The closest, I think, is this post:
https://stackoverflow.com/questions/65104246/how-to-install-powershell-core-in-aspnet-nanoserver-docker-container
From there I have been look at this DockerFile:
https://github.com/PowerShell/PowerShell-Docker/blob/master/release/7-3/nanoserver2022/docker/Dockerfile
So, I have tried to run it with the DockerFile i have added.
Running this, my Container is created and everything works, but Powershell has not been added.
From the example in Github, the escapecharacter ` is used:
But this fails with: "Syntax error - can't find = in "`". Must be of the form: name=value" so I have changed that to:
My DockerFile can be seen here:
27 replies
Manual setup of OpenTelemetry with/without Microsoft.Extensions.Hosting in a Console application
After seeing Aspire I have decided to see how OpenTelemetry, and i first created a console application following the docs on https://opentelemetry.io/docs/instrumentation/net/manual/.
However, when I tried to move it into an easier setup using the extensionsmethod available in OpenTelemetry.Extensions.Hosting i could not get it to work. I think I might just misunderstand something about how it works.
So I have this working console application, which outputs the Actitivy in the console:
I then tried using the Generic Host builder and it does not write the activity to the console:
Does anyone know why I don't see the Activity in the console output? Or maybe know how I should set the Generic Host example up?
4 replies
.NET Generic Host Writing "Application Started" when its done with its work
So I have been playing around with the Generic Host (Microsoft.Hosting.Extensions and HostedServices.
So I have this output, where "Application started" comes after my service have stopped working.
I am not sure about how, I should structure the code to get the "Application Started" before my service runs.
I am currently using StartAsync, but gets the same behaviour with RunAsync
StartAsync can be seen here: https://source.dot.net/#Microsoft.Extensions.Hosting/Internal/Host.cs,57
My Output
My Code
26 replies
Certificate Authorization using MinimalAPI
Hi,
I have been trying to authorize calls to a localhost service using certificates. Using the certificates, I can then add Clains to the client, that can be used to define what can be accessed and not accessed. This all works, and I can check the claims by accessing User from the HttpContext.
However, I would like to use the RequireAuthorization method instead, but when I enable it, it looks like my certificate is never validated.
So my authentication works when I remove the "RequireAuthorization", but I would rather use that method than getting claims from the httpcontext.
6 replies