Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Simple HTTP error message to API client

$
0
0

Hi

I want to make a very very simple Unauthorized 401 error back to my API client from my WEB API but I simply cannot figure it out.

I am getting error messages whatever I try and I have googled for some time but all threads are way overkill for what I want.

I just want something very simple like below but it tells me HTTPResponseMessage cannot be used by a method, so how do I return a simple 401 back to the client without having to use exception filters and middleware, yes I do understand those are preferred methods but this is a learning excersise for me so please humor me with a simple way of doing it directly in the web api controller.

if (ApiKey != "FooBar")
            {
                return HttpResponseMessage(Unauthorized);
            }


Viewing all articles
Browse latest Browse all 4850

Trending Articles



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