title: React component has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
body: <p>I am calling the Web API from the my react component using fetch when I used to run it as one application, there was no problem, but when I am running the application react separate from API, I am getting the CORS error, my fetch call is as below, </p>
  
  <pre><code>    componentDidMount() {
      console.log(clientConfiguration)
  
      fetch(clientConfiguration['communitiesApi.local'])
          .then((response) =&gt; {
              return response.json();                
          })
          .then(data =&gt; {
              console.log(data);
              let communitiesFromApi = data.map(community =&gt; { return { value: community, display: community } });
              this.setState({ communities: [{ value: '', display: 'Select a Community...' }].concat(communitiesFromApi) });    
  
          }).catch(error =&gt; {
              console.log(error);
          });
  };
  </code></pre>
  
  <p>and my POST call using Axios as below also. </p>
  
  <pre><code>    handleDownload = (e) =&gt; {
      e.preventDefault();
  
      var formData = new FormData();
      formData.append('communityname', this.state.selectedCommunity);
      formData.append('files', JSON.stringify(this.state['checkedFiles']));
  
      let url = clientConfiguration['filesApi.local'];
      let tempFiles = clientConfiguration['tempFiles.local'];
  
      axios({
          method: 'post',
          responseType: 'application/zip',
          contentType: 'application/zip',
          url: url,
          data: formData
      })
          .then(res =&gt; {       
              var fileName = `${this.state['selectedCommunity']}.zip`;
              saveAs(`https://localhost:44352/TempFiles/${res.data}`, fileName);
          });
  };
  </code></pre>
  
  <p>Here is my server side api code:</p>
  
  <pre><code>        [HttpGet("{communityName}")]
      public string Get(string communityName)
      {
          string rootPath = Configuration.GetValue&lt;string&gt;("ROOT_PATH");
          string communityPath = rootPath + "\\" + communityName;
  
          string[] files = Directory.GetFiles(communityPath);
  
          List&lt;string&gt; strippedFiles = new List&lt;string&gt;();
          foreach (string file in files)
          {
              strippedFiles.Add(file.Replace(communityPath + "\\", ""));
          }
  
          return JsonConvert.SerializeObject(strippedFiles);
      }
  
      [HttpPost]
      public string Post([FromForm] string communityName, [FromForm] string files) //FileContentResult
      {
          var removedInvalidCharsFromFileName = removeInvalidCharsFromFileName(files);
          var tFiles = removedInvalidCharsFromFileName.Split(',');
          string rootPath = Configuration.GetValue&lt;string&gt;("ROOT_PATH");
          string communityPath = rootPath + "\\" + communityName;
  
          byte[] theZipFile = null;
  
          using (MemoryStream zipStream = new MemoryStream())
          {
              using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
              {
                  foreach (string attachment in tFiles)
                  {
                      var zipEntry = zip.CreateEntry(attachment);
  
                      using (FileStream fileStream = new FileStream(communityPath + "\\" + attachment, FileMode.Open))
                      using (Stream entryStream = zipEntry.Open())
                      {
                          fileStream.CopyTo(entryStream);
                      }
                  }
              }
  
              theZipFile = zipStream.ToArray();
          }
  
          ////return File(theZipFile, "application/zip", communityName + ".zip");
  
          string tempFilesPath = Configuration.GetValue&lt;string&gt;("Temp_Files_Path");
  
          if (!System.IO.Directory.Exists(tempFilesPath))
              System.IO.Directory.CreateDirectory(tempFilesPath);
  
          System.IO.File.WriteAllBytes($"{tempFilesPath}\\{communityName}.zip", theZipFile);
  
          //return System.IO.File.ReadAllBytes($"{tempFilesPath}\\Test.zip");
  
          //return $"{tempFilesPath}\\{communityName}.zip";
          return $"{communityName}.zip";
      }
  </code></pre>
  
  <p>And I am getting the error for Get as below: "Access to fetch at '<a href="https://localhost:44368/api/communities" rel="noreferrer">https://localhost:44368/api/communities</a>' from origin '<a href="http://localhost:3000" rel="noreferrer">http://localhost:3000</a>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."</p>