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

ぃ、小莉子 提交于 2020-02-02 14:09:30

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/53443004/how-to-enable-cors-for-a-local-file-that-references-a-hosted-asp-net-web-api-tha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!