.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-1=021 小时前
C# IO和序列化
c#·.net·.netcore
宝桥南山2 天前
.NET 11 - 尝试一下Blazor中的新特性SupplyParameterFromTempData
microsoft·微软·c#·asp.net·.net·.netcore
1-1=03 天前
C# 特性(Attribute)
c#·.net·.netcore
淡海水4 天前
10-01-互操作-C#与C++边界的内存管理
unity·c#·游戏引擎·.netcore·gc
1-1=04 天前
C# 反射
c#·.net·.netcore
1-1=05 天前
C# 泛型
c#·.net·.netcore
淡海水7 天前
09-01-内存-Unity资源生命周期全景
unity·c#·游戏引擎·.netcore·gc
1-1=07 天前
.NET Core 编译技术
.net·.netcore
1-1=08 天前
.NET Core 文件系统
.net·.netcore·1024程序员节
1-1=09 天前
.NET Core 内存管理
.net·.netcore