.NET Core跨域

CORS

  1. 跨域通讯的问题。解决方案:JSONP、前端代理后端请求、CORS等。

  2. CORS原理:在服务器的响应报文头中通过access-control-allow-origin告诉浏览器允许跨域访问的域名。

  3. 在Program.cs的"var app=builder.Build()"这句代码之前注册

    cs 复制代码
    string[] urls = new[] { "http://localhost:3000" };
    builder.Services.AddCors(options =>
        options.AddDefaultPolicy(builder => builder.WithOrigins(urls)
        .AllowAnyMethod().AllowAnyHeader().AllowCredentials()));
  4. Program.cs的app.UseHttpsRedirection()这句代码之前增加

    cs 复制代码
    app.UseCors();
相关推荐
时光追逐者1 天前
ASP.NET Core 依赖注入的三种服务生命周期
后端·c#·asp.net·.net·.netcore
武藤一雄2 天前
C# 中线程安全都有哪些
后端·安全·微软·c#·.net·.netcore·线程
csdn_aspnet2 天前
.NET 8 Web 应用、Web API 和 RabbitMQ
rabbitmq·.netcore·.net8
温暖的苹果3 天前
【.Net runtime】corehost(.NET 应用启动过程)
c#·.net·.netcore
csdn_aspnet3 天前
使用 Windows 客户端的 RabbitMQ Messaging for .NET 8 Web API 第 2 部分
windows·rabbitmq·.netcore·.net8
csdn_aspnet3 天前
使用 Windows 客户端的 RabbitMQ Messaging for .NET 8 Web API 第 1 部分
rabbitmq·.net·.netcore·.net8
csdn_aspnet4 天前
ASP.NET Core:创建并验证文档上的数字签名
.netcore·数字签名
喵叔哟8 天前
12.云平台部署
后端·.netcore
爱吃香蕉的阿豪8 天前
NET Core中ConcurrentDictionary详解:并发场景下的安全利器及服务端实践
安全·http·.netcore·高并发
武藤一雄9 天前
彻底吃透.NET中序列化反序列化
xml·微软·c#·json·.net·.netcore