.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();
相关推荐
csdn_aspnet4 天前
MongoDB C# .NetCore 驱动程序 序列化忽略属性
mongodb·c#·.netcore
Tiger_shl5 天前
【.Net技术栈梳理】08-控制反转(IoC)与依赖注入(DI)
开发语言·.net·.netcore
Tiger_shl5 天前
【.Net技术栈梳理】10-.NET Core 程序的执行
开发语言·.net·.netcore
MoFe15 天前
【.net core】【watercloud】登陆后跳转至指定页面,显示在系统框架页内
.netcore
周杰伦fans5 天前
.net core webapi/mvc阿里云服务器部署 - 错误解决
阿里云·mvc·.netcore
驾驭人生8 天前
Asp .Net Core 系列:Asp .Net Core 集成 Hangfire+MySQL
数据库·mysql·.netcore
时光追逐者8 天前
C#/.NET/.NET Core技术前沿周刊 | 第 53 期(2025年9.1-9.7)
c#·.net·.netcore
somethingGoWay9 天前
wpf .netcore 导出docx文件
wpf·.netcore
somethingGoWay9 天前
wpf .netcore 导出pdf文件
pdf·wpf·.netcore
切糕师学AI10 天前
如何建立针对 .NET Core web 程序的线程池的长期监控
java·前端·.netcore