Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Middleware create requestcode 500 allthroug i set 401

$
0
0

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);
        }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>