3

Hi I am using django rest framework as API service and React as frontend.I can call the api from react when developing and when i deploy to iis.I got this error

No 'Access-Control-Allow-Origin' header is present on the requested resource.

I already do like this say=>CORS Error

but I still got this error.

My Django runs on localhost:81

My react app run on : 192.168.1.32:81

I can run this on local server which both installed but when I try on another computer I got this error.

I used the fiddler 4 for override the port in the hostname.

Loran
  • 772
  • 4
  • 16
  • 38
  • Does this answer your question? [No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API](https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe) – pkamb Nov 20 '20 at 07:58

2 Answers2

4

You could use iis response header:

1)open iis manager and select the site.

2)Double-click HTTP Response Headers from the middle pane.

enter image description here

3)In the actions pane, click Add.

enter image description here

4)In the Name box, type the custom HTTP header name. In the Value box, type the custom HTTP header value.

below is header and value:

Access-Control-Allow-Origin:*

Access-Control-Allow-Headers: Content-Type

Access-Control-Allow-Methods:GET,POST,PUT,DELETE,OPTIONS

Access-Control-Allow-Credentials: true

5)Click OK.

enter image description here

or you can directly add below code in the web.config file:

<system.webServer>
      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
          <add name="Access-Control-Allow-Headers" value="Content-Type" />
          <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
         <add name="Access-Control-Allow-Credentials" value="true" />
        </customHeaders>
      </httpProtocol>
  </system.webServer>
Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
0

Use this command in run (windows key + r) and run your app in the new browser

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

I hope it works as you want

behzad
  • 801
  • 3
  • 15
  • 33