Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

so im trying to filter que requests to an api, to process some filed in the header, i used ,mapwhen(), i can filter do what i want but then the process doesn continue, basicaly return nothing it doesnt go to the controller.

what i am missing?

What I have tried:

C#
app.MapWhen(context => 
context.Request.Headers.ContainsKey("value"),
                (appbuilder) =>
                    {
                    //appbuilder.Run(async (context) =>  { await context.Response.WriteAsync("Tinha ano"); });
                    appbuilder.Use(async (context, next) =>
                    {
                        Microsoft.Extensions.Primitives.StringValues value;

                        context.Request.Headers.TryGetValue("value", out value);
                                               

                        if (vaue != "5")
                        {
                            await Task.FromResult(context.Response.StatusCode = StatusCodes.Status406NotAcceptable);
                        }
Posted
Comments
Richard Deeming 26-Nov-21 6:48am    
await Task.FromResult(...) makes no sense at all.

Also, you're not calling the next item in the pipeline based on the code you've shown.
Maxpaine69 26-Nov-21 8:00am    
yes that what was missing, From result, was only to send a status code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900