英文:
Ionic app error: No 'Access-Control-Allow-Origin' header is present on the requested resource
问题
我有一个使用Ionic Capacitor开发的移动应用程序。该应用程序的后端是部署在Amazon Elastic Beanstalk上的.NET Core Web API。当尝试使用该应用程序访问后端时,我收到了CORS错误未在请求的资源上出现'Access-Control-Allow-Origin'标头。
我尝试允许任何消费者访问API,允许所有来源。是否需要在AWS Elastic Beanstalk上配置任何内容?
var app = builder.Build();
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);
英文:
I have a mobile app developed in ionic capacitor. The backend to the app is a .net core web api deployed on amazon elastic beanstalk. I am getting CORS error** No 'Access-Control-Allow-Origin' header is present on the requested resource** when trying to access the back end using the app.
I have attempted to allow the API to be accessible by any consumer by allowing all origins. Is there need to configure anything on AWS Elastic bean?
var app = builder.Build();
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);
答案1
得分: 0
- 登录到AWS管理控制台,然后导航到弹性Beanstalk服务。
- 选择您的应用程序和部署了.NET Core Web API的环境。
- 在导航窗格中,点击“配置”。
- 在“软件”部分下,点击“编辑”以修改“环境属性”。
- 添加一个新的属性,具体如下:
- 名称:
ACCESS_CONTROL_ALLOW_ORIGIN
- 值:
*
(或者如果不想允许所有来源,可以指定特定的来源)
- 名称:
- 保存更改,等待环境更新。
确保从您的.NET Core Web API代码中删除您提到的CORS配置,因为现在CORS处理将由弹性Beanstalk处理。
英文:
- Log in to the AWS Management Console and navigate to the Elastic Beanstalk service.
- Select your application and environment where the .NET Core Web API is deployed.
- In the navigation pane, click on "Configuration."
- Under the "Software" section, click on "Edit" for the "Environment properties."
- Add a new property with the following details:
- Name:
ACCESS_CONTROL_ALLOW_ORIGIN
- Value:
*
(or the specific origin you want to allow if you don't want to allow all origins)
- Name:
- Save the changes and wait for the environment to update.
Make sure to remove the CORS configuration you mentioned from your .NET Core Web API code, as the CORS handling will now be done by Elastic Beanstalk.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论