net core 3.1 跨域 Cors 找不到 “Access-Control-Allow-Origin”
首先在ConfigureServices添加
public void ConfigureServices(IServiceCollection services){services.AddCors(options =>{options.AddPolicy("any", builder =>{//builder.AllowAnyOrigin() //允许任何来源的主机访问 builder.WithOrigins("http://*.*.*.*")//.SetIsOriginAllowedToAllowWildcardSubdomains()//设置允许访问的域 .AllowAnyMethod().AllowAnyHeader().AllowCredentials();// });});services.AddControllers();}
然后新增
public class CorsMiddleware{private readonly RequestDelegate _next;public CorsMiddleware(RequestDelegate next){_next = next;}public async Task Invoke(HttpContext context){if (!context.Response.Headers.ContainsKey("Access-Control-Allow-Origin")){context.Response.Headers.Add("Access-Control-Allow-Origin", "*");}await _next(context);}}
然后 使用中间件
app.UseMiddleware<CorsMiddleware>();
net core 3.1 跨域 Cors 找不到 “Access-Control-Allow-Origin”相关推荐
- 第5章 uin-app本地主机数据跨域(Cors)数据交互实现
开发前端App最先需要被实现的功能是:与本地主机上已经布置在IIS服务上的后端数据实现跨域(Cores)交互操作,这也是前端App作为前端工程性项目存在的根本意义和需求,因此需要首先对上一章中示例:2 ...
- 跨域 -- cors
Origin . Host . Referer 1.1 Origin -简单请求 GET HTTP/2 Origin: https://h5test.selfshero.com Referrer Po ...
- 跨域(CORS)请求问题[No 'Access-Control-Allow-Origin' header is present on the requested resource]常见解决方案
基本概念 跨域(CORS)请求:同源策略/SOP(Same origin policy)是一种约定,由Netscape公司1995年引入浏览器,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略, ...
- Node跨域cors模块,nodejs+express跨域
Node跨域cors模块 NodeJS+Express跨域 什么是CORS CORS(Cross-origin resource sharing),跨域资源共享,是一份浏览器技术的规范,用来避开浏览器 ...
- 跨域 cors 请求两次_请求两次的故事-CORS
跨域 cors 请求两次 The story of requesting twice, allow me to explain how it all began. 请求两次的故事,让我解释一下这是如何 ...
- k8s下使用Ingress开启跨域(CORS)
在Ingress中,跨域(CORS)的配置如下: nginx.ingress.kubernetes.io/cors-allow-headers: >-DNT,X-CustomHeader,Kee ...
- ajax中cors解决跨域,AJAX 跨域 CORS 解决方案
两种跨域方法 在 Javascript 中跨域访问是比较常见的事情 就像现在比较流行写单页应用,而单页应用在访问 API 的时候就会有跨域的问题 要解决跨域的问题,其实也并不复杂,有两种方案可以选择 ...
- AJAX(GET POST请求、 jQuery axios 发送请求、跨域--cors、请求超时、网络异常、放弃请求、重复发送请求)
根据视频进行整理 [https://www.bilibili.com/video/BV1WC4y1b78y?p=1] 视频资料 百度网盘: 链接:[https://pan.baidu.com/s/1n ...
- 面试--跨域--cors
cors是什么 cors 跨域资源共享 Cross-origin resource sharing是一种跨域的解决方案 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从而克服了AJA ...
最新文章
- 中国女博士的「水淹食堂」大法:单目视频完美重建3D场景,画面毫无违和感...
- 宏基因组理论教程7挖掘微生物组生物标记
- Theano 中文文档 0.9 - 7.2.5 循环
- java并发编程同步器 Semaphore、CyclicBarrier、Exchanger、CountDownLatch
- jquery selector 使用方法
- java reduce.mdn_reduce高级用法
- PhotoShop常用的功能汇总
- Mining Precision Interface From Query Logs -- 学习笔记(二)
- Flask Middle
- 增长率方程用c语言,资料分析常用公式
- Android Studio报错提示:Excepted resource of type color
- NYOJ54-小明的存钱计划
- JZOJ【NOI2017模拟3.30】原谅
- windows10官网下载安装(纯净版)
- 使用vue-print-nb打印element table时表格打印不全的问题
- 第13期微生物组-宏基因组分析(线上/线下同时开课,2021.11)
- sfc/scannow检查并修复window系统
- JSP与数据库的连接方法
- Object of type type is not JSON serializable
- 谷歌浏览器使用迅雷下载资源