简体   繁体   中英

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

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-* .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM