[英]CORS error in dev environment; works OK locally
I am trying to make an api call from a vue application to a .net core web api.我正在尝试从 vue 应用程序向 .net core web api 进行 api 调用。 Locally this works, when we then run it on our first dev environment we get this when it trys to make the request
在本地这是有效的,当我们然后在我们的第一个开发环境中运行它时,我们会在它尝试发出请求时得到这个
Access to XMLHttpRequest at ' https://bla-api/api/foc?page=1&pageSize=10&sortBy=&sortDirection=ASC ' from origin ' https://bla-api ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
在“ https://bla-api/api/foc?page=1&pageSize=10&sortBy=&sortDirection=ASC ”从源“ https://bla-api ”访问 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应没有't pass access control check: 请求的资源上不存在'Access-Control-Allow-Origin'标头。
I have added the following to the C#' Startup file in the ConfigureServices method.我已将以下内容添加到ConfigureServices方法中的 C# 启动文件中。 To just get it working I wanted to provide the *(wildcard), so let anyone call this.
为了让它工作,我想提供*(通配符),所以让任何人都称之为。 So presume that the named policy AllowAnyOrigin would do this!?
所以假设命名策略 AllowAnyOrigin 会这样做!?
readonly string _SpecificOrigins = "AllowSpecificOrigins";
services.AddCors(options =>
{
options.AddPolicy(_SpecificOrigins,
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
})
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
then also added this in the Configure method然后也在配置方法中添加了这个
app.UseCors(_SpecificOrigins);
app.UseMvc();
What am I missing?我错过了什么? I also try and make a fiddler request to the api and it breaks.
我还尝试向 api 发出提琴手请求,但它中断了。 Any help would be greatly appreciated
任何帮助将不胜感激
This was a red herring, the web api was not even deployed correctly, it was being deployued as a kestrel exe but was deployed as an azure web app.这是一个红鲱鱼,甚至没有正确部署 web api,它被部署为 kestrel exe,但被部署为azure web 应用程序。 Adding a web.config pointing to the main api project resolved the issue.
添加指向主 api 项目的 web.config 解决了该问题。 I did not write the deployment so that no needs looking at next.
我没有写部署,所以不需要看下一步。 Presume the above question is fine then, cheers for the help
那么假设上述问题没问题,为帮助欢呼
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.