Why am I getting a 401 error when trying to access a running plain vanilla (unmodified) Web API app from Postman?

I'm refreshing my Web API knowledge by reading ASP.NET Web API Succinctly. It has a simple example of using Postman to get some of the app's predefined data, entering the following into Postman using the Get verb:

http://localhost:52194/api/values

The Web API is running, and shows "http://localhost:52194/" in my (Chrome) browser.

Sending the above Get verbed URL from Postman, though, results in a "401 Unauthorized" in Postman.

Theoretically, I should see:

[
    "value1",
    "value2"
]

...because of this code existing in the app:

namespace PlatypusWebReports.Controllers
{
    [Authorize]
    public class ValuesController : ApiController
    {
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
        . . .

Why am I getting a "401" and how can I prevent it?

Upvotes: 0

Views: 1078

Answers (1)

Sergey Popov
Sergey Popov

Reputation: 538

You have this error because you marked your controller class with Authorize attribute. Just remove this attribute if you really don't need authorization for this API.

Upvotes: 3

Related Questions