Custom web api calling through JQuery showing CORS error in sharePoint 2019 onpremise.

Mohammad Javed 151 Reputation points
2020-11-10T06:02:35.587+00:00

Custom web api calling through JQuery showing CORS error in sharePoint 2019 onpremise.38657-errorscreenshot.png

Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

Accepted answer
  1. Baker Kong-MSFT 3,801 Reputation points
    2020-11-11T02:44:54.807+00:00

    Hi @Mohammad Javed ,

    This is a CORS issue. Only when the protocol, host and port is the same, then it could be considered as the Same Origin Policy.

    You may need to modify some settings on the Web config file or rewrite the IIS rules. Please check below similar thread:

    If you want to exactly math the specified url, you can change the catch url condition in inbound rule like below:

    <rules>  
            <rule name="inboundrule" patternSyntax="ECMAScript" stopProcessing="true">  
              <match url=".*" />  
              <conditions logicalGrouping="MatchAll">  
                            <add input="{HTTP_ORIGIN}" pattern="(http(s)?://((.+\.)?andyweb2\.azurewebsites\.net|(.+\.)?ggg\.devchatline\.com))" />  
                            <add input="{REQUEST_METHOD}" pattern="^OPTIONS$" />  
              </conditions>  
              <action type="CustomResponse" statusCode="200" statusReason="Preflight" statusDescription="Preflights" />  
            </rule>  
    </rules>  
    

    *Note that not forgot to replace the pattern with your own value.

    More reference:

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.