.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();
相关推荐
geovindu20 小时前
CSharp: Observer Pattern
开发语言·后端·观察者模式·设计模式·c#·.netcore·行为模式
geovindu1 天前
CSharp: Strategy Pattern
开发语言·后端·c#·.net·.netcore·策略模式·行为模式
geovindu1 天前
CSharp: Task Scheduler
开发语言·后端·c#·.net·.netcore
geovindu7 天前
CSharp: Wordcloud
开发语言·后端·c#·.net·.netcore·词云
geovindu7 天前
CSharp: Command Pattern
开发语言·后端·c#·.net·.netcore·命令模式·行为模式
全栈小515 天前
【C#】.net core,静态方法线程安全解析,面试时经常被问的线程安全就藏在里面
安全·c#·.netcore
清风与日月17 天前
Yitter.IdGenerator:高性能分布式唯一ID生成器详解
分布式·c#·.net·.netcore
Lost of 程序猿20 天前
ASP.NET Core 后台任务全景:从 BackgroundService 到 Channel 队列,再到分布式调度
后端·asp.net·.netcore
宝桥南山21 天前
Blazor Web Assembly - 体验一下Authentication State从Server共享给Client
microsoft·微软·c#·asp.net·.net·.netcore
宝桥南山1 个月前
Microsoft Agent Framework(.NET) - 尝试一下从MCP Server上获取Agent Skills
ai·微软·c#·aigc·.net·.netcore