Web API (.NET Core 3.1) lives in SharePoint _layouts folder

SHUO .H 706 Reputation points
2021-10-16T14:19:14.49+00:00

Hi there,

I used .NET Core 3.1 to create a Web API for specific purpose. I build up this API in SharePoint Farm and put it in the _layouts folder. I have another system called (A) will call this. We use the ADFS authentication.

I try to use two accounts from ADFS and try this. I got two different results.

(1) Account 1: It works well and (A) can put the data into the backend database via this custom API
(2) Account 2: Failed and I got the following error message:

Access to XMLHttpRequest at ''* from origin (https://adfs.litwareinc.com/adfs/ls? .....) *'
(redirected from 'https://intranet.litwareinc.com/_layouts/15/FolderName/APIHub.aspx?Mode=....') from origin 'https://intranet.litwareinc.com'
has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a prefight request.

and

net :: ERR_FAILED

I am wondering if anyone have ran into this before and have any idea on it?

Thanks

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,221 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,369 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,158 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,573 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2021-10-16T15:36:08.937+00:00

    Generally this is caused by the server the ajax called redirecting to the login page rather than retuning an error on failed authentication. Because login pages don’t support CORS (they are html), you get this CORS error rather being unable to parse the response.

    0 comments No comments