Hallo,
i create a middleware for my API Requests. When i set 401 i get a 500 server error. i think, the middleware steps to the next middleware (identity). if i set the 400 code, i will request the right badrequest code. can someone told me, how i set 401.
public async Task Invoke(HttpContext context) { if (context.Request.Path.StartsWithSegments("/api")) { context.Response.StatusCode = 401; await context.Response.WriteAsync("Authentifizierung notwendig."); return; } await _next.Invoke(context); }