373 questions
4
votes
1
answer
356
views
Why Visual Studio is telling me to replace argument with HttpContext when I use TypedResults.NotFound?
So, I got this little minimal api endpoint:
app.MapGet("/person/{name}", (string name) =>
{
var person = people.FirstOrDefault(p => p.Name.StartsWith(name));
if (...
0
votes
0
answers
397
views
Swagger UI failed to serialize object with Minimal API .NET 8
I setup Minimal API with .NET 8 and enable Swagger and Swagger UI.
var builder = WebApplication.CreateBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options....
0
votes
1
answer
74
views
Kestrel doesn't like trolling the attacker with bogus root escapes much
So I had this brilliant idea to troll the attacker by setting up a nonsense response to faking a path escape.
At one time this used to do something interesting
GET /../../etc/passwd HTTP/1.0
So I ...
0
votes
1
answer
116
views
app.MapDynamicControllerRoute<Router>("{**path}") doesn't seem to affect routing
Edit:
The problem was that app.UseRouting(); was called before app.Use(async (context, next) => {...}). Once I place everything in this order, it worked:
app.Use(async (context, next) { ... });
app....
1
vote
1
answer
578
views
Minimal API endpoint not allowing null for nullable int?
I have set up a .NET 8 Minimal API with an endpoint that accepts two query parameters, one is an int? and one is a string?.
Route.MapGet("/SearchForServiceCompany",
(IMapper ...
-1
votes
1
answer
861
views
MSAL acquireTokenSilent makes new request everytime, cache is ignored
@azure/msal-browser 3.20.0
@azure/msal-react: 2.0.22
I have SPA react client app, and API on backend.
I made two App registrations, exposed custom api, consented as admin.
Everything works, i ...
0
votes
1
answer
641
views
Header based routing in ASP.NET Core Minimal API
I'm looking for a way to have multiple routes in my ASP.NET Core which differ by a certain header. I found this question which answers the same question BUT for a controllers-based API: Header based ...
3
votes
2
answers
675
views
Model Binding of dictionary in .NET 8 Minimal API
When someone calls my api endpoint (Minimal API), I would like to pull a dictionary from the query string.
I have the following query parameter struct for my Minimal API endpoint (simplified for this ...
0
votes
1
answer
251
views
ASP.NET Core 8 Minimal API : read Windows environment variable as authentication token
I should read an environment variable that I stored at the Windows operating system level, which contains an authentication token that my middleware class uses to authenticate me with my ASP.NET Core ...
2
votes
1
answer
1k
views
The type cannot be used as a type parameter in the generic type or method
I'm writing my first application using minimal APIs in a .NET 8 application. I'm following a training exercise I found on Microsoft Learn, and I'm using a database I designed. I ran into this error:
...
2
votes
1
answer
176
views
Model binding of dictionaries as part of a form in Minimal API
If you take a look at this blog post:
https://libertus.dev/posts/apsnet-dictionary-model-binder/
I'm trying to achieve exactly the same, just with the minimal api.
In the documentation
https://learn....
0
votes
0
answers
248
views
AspNetCore Minimal API How Catching Error Binding Parameters?
I use .NET 8 and I have minimal API in ApsNetCore. I have this GET method with param bindings using StronglyTypedId:
internal static async Task<Results<Ok<PaginatedList<TestResultDto>&...
1
vote
1
answer
648
views
From a minimal ASP.NET Core Web API how do I return a JObject while maintaining the nested elements?
I am building a minimal ASP.NET Core Web API. One of my endpoints needs to return data contained in a JObject. This JObject represents a complex nested data structure. What I am finding is that the ...
0
votes
1
answer
101
views
Status code http 500 in .NET Core Minimal API, EF, SQLite. Works locally but doesn't work on Azure
I built a Minimal API using EF, Sqlite and C#. It works locally, but once I deploy it to Azure, I get a http 500 status code and a SQLite error that the table doesn't exist. I don't know if it doesn't ...
-1
votes
2
answers
1k
views
ASP.NET Core 8 Minimal API throws 404 on deploy in IIS
When I publish my ASP.NET Core 8 Minimal API project using these settings:
Configuration: Release
Target framework: net8.0
Target runtime: Portable
on IIS on a Windows Server 2012 R2, I always get ...
1
vote
1
answer
304
views
Asserting IResult when retuning an Anonymous Type
I am learning Minimal APIs (and also still learning C#), but just got stuck when creating Unit Tests. Given this function:
public IResult GetGenderById(Guid id)
{
var gender = this....
1
vote
1
answer
683
views
.NET 8 Minimal API return JSON string as Json without first deserialize into an object
If I have a string (which is already in JSON format) say
string JsonStr = "{ 'A': 123 }";
My API is
public JsonResult OnGetRetrieve()
{
string JsonStr = "{ 'A': 123 }";
...
2
votes
2
answers
1k
views
What is the difference between the .NET Minimal API and .NET AOT and how does it relate to each other if they are?
I have searched on the Internet, and I couldn't find a concrete explanation regarding this.
I have used the Minimal API before, and when I am using the .NET AOT, the project source code seems ...
1
vote
1
answer
2k
views
ASP.NET Core Minimal API redirect that changes uri
I've done a couple of hours of searching after some failed attempts, and I'm hoping someone can provide a little clarity.
In the olden days, response.Redirect could be used in a web application to ...
1
vote
1
answer
243
views
How to handle separate authentication for mixed Blazor Server App and Minimal Api
I would like to combine a blazor server app with a minimal api as additional option for users to access data.
The blazor app uses windows authentication:
builder.Services.AddAuthentication(...
0
votes
1
answer
43
views
404 NOT FOUND error when calling endpoint with required claim
I have the following setup:
var services = builder.Services;
services.AddAuthentication(IdentityConstants.BearerScheme)
.AddBearerToken(IdentityConstants.BearerScheme);
services....
0
votes
1
answer
88
views
.NET Core json response differences between Chrome and Firefox
I wrote a Minimal Web API with this code:
app.MapGet("/api/getLogs", async (HttpContext context) =>
{
context.Response.Headers.ContentType = "application/json";
data =...
3
votes
2
answers
1k
views
Set the same 'Produces' response for all Minimal API endpoints
in .NET 8, in a project with a minimal API, is it possible to set status codes, for example, 401 Unauthorized, on all endpoints with a single call to a method, for example:
app.MapGroup("test&...
1
vote
0
answers
347
views
Visual Studio 2022 Publish Fails - Unable to delete files
I am trying to Publish a sample DotNetCore project (from the basic VueJs/Core solution template) to an IIS server with the 'Delete Existing Files' option. If the app has been running, then the Publish ...
0
votes
1
answer
528
views
.NET 8 Minimal API - Finding Endpoints using NSwag that use AddEndpointFilter
I am using currently using AddEndpointFilter for my endpoint using MinimalAPI
app.MapGet("/{Id}", Method).AddEndpointFilter<HeaderFilter>()
Using NSwag's OperationProcessor, I want to ...
0
votes
1
answer
269
views
React with .NET 8.0 + Minimal api, frontend sends http requests to its own port instead of backend port
Previously I was working with react projects on .NET 3.1, and I just tried to create a fresh project on .NET 8.0 and encountered a lot of troubles and misunderstandings. I created a new controller and ...
1
vote
3
answers
475
views
send object with GetFromJsonAsAsyncEnumerable
Working with .net8.0 Blazor Web App with MinimalAPI and FastEndpoints. Currently, to send an object to a get request that returns a list I'm using
var req = new GetAgencyListRequest()
...
1
vote
2
answers
246
views
Get AppSettings from Azure AppConfiguration before web application build
My minimal web api use Azure App Configuration to store several configuration settings.
Now I need to get some values from that configurations before .Build() the web application and I can't find a ...
0
votes
2
answers
3k
views
Minimal API requires TryParse() on input model despite ModelBinder
I'm trying to implement a single ModelBinder for all my DTOs:
public class MyModelBinder : IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext) {
var queryDto = ...
1
vote
1
answer
530
views
Equivalent of ConfigureApiBehaviorOptions() for Minimal APIs
In an ASP.NET Core application, if you use AddMvc() or AddControllers(), you can configure the default behaviour in case the input DTO is invalid, like:
services.AddControllers()
....
1
vote
1
answer
530
views
ASP.NET custom middleware after authorization/authentication
I wanted to have my API support AOT so I've decided to move away from MVC Controllers.
I don't like the minimal API approach though so I've decided to write my own middleware to handle the requests ...
0
votes
1
answer
415
views
How to see console output from Minimal API when debugging in IDE
With Azure Functions, when I run in the IDE it brings up a console. With a Minimal API project it does not do this, however I can run it with "dotnet watch" from a terminal and see the ...
0
votes
2
answers
3k
views
Versioning by header in ASP.NET Core Minimal API
I have an ASP.NET Core Minimal API. I want to version an endpoint using request header X-Api-Version. Depending on the version I want to do different things.
Something like this:
app.MapPost("/...
2
votes
1
answer
1k
views
How to do Integration Testing with FastEndpoints and .NET 8 WebApplicationBuilder?
I have a .NET 8 minimal API setup:
var builder = WebApplication.CreateBuilder(args);
var app = builder.ConfigureApp();
app.Run();
// Reference for Testing Purposes of FastEndpoints
namespace BeeHive....
1
vote
1
answer
176
views
Is there a way to make the ASP.NET Core model binder set properties with private setters?
I use ASP.NET Core minimal APIs and I try to have my view-models (where incoming client data gets mapped to) use private setters for their properties.
But I see that the binding stops working once I ...
0
votes
1
answer
1k
views
How do I replicate [FromBody] Web API functionality with Minimal APIs?
In ASP.NET Core Web API, I may have an endpoint as follows:
[HttpPost("doSomething")]
public async Task<IActionResult> DoSomething([FromBody] SomeObject request)
{
// ...
}
With ...
5
votes
1
answer
4k
views
.NET Minimal API mapping List<T> parameter as [FromQuery]
I want to map List<T> from query string in .NET 8 Minimal API.
Tried like this:
public record ColumnFilterDto(string Column, object Value);
app.MapGet("/", (
[FromQuery] List&...
3
votes
1
answer
2k
views
ASP.NET Core - Is it possible to apply a filter for all minimal API endpoints?
I want to apply a filter to all asp.net core minimal API endpoints.
The reason I want to do this is to post-process the return values of the endpoint. Something like this:
public class ...
3
votes
1
answer
1k
views
ASP.NET Core Results.File vs Results.Stream
I am returning a file from my ASP.NET Core API using this code:
app.MapGroup("file").MapGet("/export", async () =>
{
var fileStream = someCode1();
var fileType= ...
2
votes
2
answers
80
views
Dynamically Creating a Func<> Delegate in F# Based on a Passed Function
I'm working on developing an F# wrapper for ASP.NET Core's minimal API to make route handlers more idiomatic to F#. My current implementation for a simple GET endpoint looks traditionally C#-ish:
app....
0
votes
3
answers
2k
views
How to apply `[Authorize(AuthenticationSchemes = "Api")]` with Minimal API in ASP.NET Core?
I am trying to to Minimal API in an ASP.NET Core app. I added the following endpoint
app.MapPost("api/content", CallbackAsync);
The defined the CallbackAsync as a static function as the ...
1
vote
1
answer
1k
views
ASP.NET Core Minimal API POST verb raw body swagger empty parameters
I'm using an ASP.NET Core Minimal API, the POST operation reads raw data:
app.MapPost("/Authenticate", async (HttpRequest Request) => {
string rawContent = string.Empty;
using (...
1
vote
0
answers
426
views
asp.net minimal API, validation of a primitive parameter, and OpenAPI documentation
I have working code but am hoping there is a better way...
Problem:
annotate a parameter in a method used in a minimal API in a way that informs OpenAPI (but does not mislead a future developer -- ...
1
vote
1
answer
2k
views
ProblemDetails not working when returning TypedResults.BadRequest<string>
I have this sample of an ASP.NET Core 8 application using ProblemDetails.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddProblemDetails();
var app = builder.Build();
app....
1
vote
1
answer
101
views
How to retrieve all Claims from multiple schemes?
There is a need to do multistage authentications. For example, first login as a plain user with scheme1 (longer enough lifespan of cookie) and an additional login as a super user with scheme2 (short ...
1
vote
1
answer
790
views
AsParameters in Minimal Apis does not load nested objects from the querystring
I'm using Minimal Apis together with MediatR and I'm having a problem passing parameters via querystring, below the querystring:
/api/Relogio?Name=&ProductRef.Code=asdsadsadsadsadasdsasadsa&...
3
votes
1
answer
3k
views
Accept Content-Type:text/json request in Minimal API
I am currently using .NET8 and Minimal API to handle requests. Everything works perfectly when a request has a header with the value Content-Type: application/json. However, when the 'Content-Type' is ...
2
votes
1
answer
1k
views
Cannot get Minimal API .NET 8 AOT lambda to work
I'm kind of new to AWS, but trying out the lambdas for minimal api aot for .NET 8. Using the ".NET 8(C#/F#/Powershell)" runtime, with the x86_64 architecture. Built the lambda with the "...
3
votes
1
answer
430
views
Using enums in routes
When using controllers you can use enums in routes but you have to add the following
builder.Services.AddControllers();
.AddJsonOptions(options =>
options.JsonSerializerOptions....
7
votes
2
answers
5k
views
Using DataAnnotation Model Validation in Minimal Api
I am porting an application from Asp.net Controllers to Asp.net Minimal-Apis. The current project is using model-based DataAnnotations. Controllers do model validation out of the box but MinApi does ...