api netcore 跨域支持_aspdotnetcore 跨域问题

在ASP.NET Core 2.2的WebAPI项目中,前端使用Vue进行请求时遇到了跨域问题。错误信息显示缺少'Access-Control-Allow-Origin'头。在 Startup.cs 文件中,已经尝试通过 `services.AddCors()` 添加跨域支持,并在 Configure 方法中设置了允许来自 'http://localhost:8080' 的来源。然而,请求仍然被阻止。解决方案可能在于进一步配置 Cors 政策以确保正确设置响应头。
摘要由CSDN通过智能技术生成

前端是 vue 后端是aspdotnet core 2.2的 webapi

前端调用后端接口的时候不通:

Access to XMLHttpRequest at 'http://127.0.0.1:13037/api/user/authenticate' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

应该是跨域的问题,不知道的怎样才能让这个'Access-Control-Allow-Origin'加出来

接口的Startup中应该是已经用了跨域了

public void ConfigureServices(IServiceCollection services)

{

services.AddCors();

// configure strongly typed settings objects

var appSettingsSection = Configuration.GetSection("AppSettings");

services.Configure(appSettingsSection);

// configure jwt authentication

var appSettings = appSettingsSection.Get();

var key = Encoding.ASCII.GetBytes(appSettings.Secret);

services.AddAuthentication(x =>

{

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值