poojay
poojay

Reputation: 155

I received error 401 : unauthorized when accessing my web API

I'm trying to run one of my web app APIs but when prompted for user and password, it responded with 401 access denied. I've tried changing from NTLM to Kerberos. It still won't work. I'm new to SharePoint.

This is how I call my API :

var json = $.ajax({
        url: (serviceType == "wcf" ? wcfServicesUrl : servicesApi) + wcfServiceUri,
        type: type,
        data: data,        
        crossDomain: true,
        contentType: "application/json",
        dataType: "json",
        xhrFields: {
            withCredentials: true
        }
)};

Upvotes: 4

Views: 21716

Answers (4)

Husokanus
Husokanus

Reputation: 53

Try below solution, it worked in my case. First open IIS and click your site. And then:

  1. Right click "Authentication"
  2. Click "Open Feature"
  3. Select "Anonymous Authentication"
  4. Select "Edit" From "Actions" on the right
  5. Select "Application Pool Identity"
  6. Click "Ok"

Upvotes: 0

Alexander Meise
Alexander Meise

Reputation: 1438

401 can also be NTFS permissions, take a look here:

Upvotes: 0

Umer Siddiqui
Umer Siddiqui

Reputation: 1

i have recently came across production issue where my PRODUCTION API server suddenly starts giving 401 unauthorized error , I searched a lot on internet but fruitless than I took support from Microsoft as this application was running fine , suddenly the error occurred , Microsoft just took a look on which dot net frame work the application is using mine was 4.0 , so they advised to go to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files

when an application is hosted on IIS , it compiles its dlls and other files once in this particular folder ,if it gets lock or corrupt the application will start giving 401 unauthorized error and delete the temp files and restarted IIS and Voala it start working . Please mark it as a answer if you are comfortable

Upvotes: 0

Glenn Ferrie
Glenn Ferrie

Reputation: 10410

You need to adjust the authentication settings in IIS for your Web API application.

IIS Screenshot

Depending on what you are trying to do, you may need one or more of these options enabled.

Your app pool identity also plays a role. Make sure they user is properly authorized to access your content / data / etc.

Update: set Windows Authentication as Enabled, make sure all others are disabled. Do not use Kerberos. Add URL for your web app to Trusted Sites in your browser.

Upvotes: 0

Related Questions