Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CORS for a local file that references a hosted ASP.NET Web API that is hosted on Amazon AWS

So when I open a file that references a hosted ASP.NET Web API 2.0 project, I get the error:

Possible cross-origin (CORS) issue? The URL origin (https://secreturl.amazonaws.com) does not match the page (file://). Check the server returns the correct 'Access-Control-Allow-*' headers.

I only get answers for enabling cores for an HTTP request pipeline but not for (file://). I open the file from an index.html file, with path file:///C:/Users/PCName/desktop/index.html I assume the CORS have to be enabled in the Startup.cs file in the ASP.NET Core Web API 2.0

like image 812
MswatiLomnyama Avatar asked Nov 23 '18 08:11

MswatiLomnyama


1 Answers

Most browser implementations by default do not support CORS headers for local files (specifically they set the value to null which cannot then be used in an Access-Control-Allow header.)

The easiest thing to do is start a small server. If you've got Python installed, this is as easy as running python3 -m http.server 8000 in the C:/Users/PCName/desktop directory, and then you can browse to localhost:8000 (there are other 'instant servers' out there!).

That way you can use Access-Control-Allow-*.

like image 198
thomasmichaelwallace Avatar answered Oct 21 '22 03:10

thomasmichaelwallace