网页请求报错:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

如图:

跨域问题解决原理

CORS全称Cross-Origin Resource Sharing,中文全称跨域资源共享。它解决跨域问题的原理是通过向http的请求报文和响应报文里面加入相应的标识告诉浏览器它能访问哪些域名的请求。

比如我们向响应报文里面增加这个Access-Control-Allow-Origin:http://localhost:8081,就表示支持http://localhost:8081里面的所有请求访问系统资源。

其他更多的可以去网上找找。

在.net Core解决方案

WebApi项目中的

  • Startup.cs类方法体 ConfigureServices 内加上

  services.AddCors(options =>
{
options.AddPolicy(anyAllowSpecificOrigins, corsbuilder =>
{
var corsPath = Configuration.GetSection("CorsPaths").GetChildren().Select(p => p.Value).ToArray();
corsbuilder.WithOrigins(corsPath)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();//指定处理cookie
                });
});
  • appsettings.json加上以下配置

  "CorsPaths": { //配置跨域的地址【跨域地址加到这里就可以访问 "参数名":"跨域地址"】
"OriginAll": "*",
"OriginOnA": "http://localhost:8080",
"OriginOneC": "http://localhost:8081",
"OriginOneD": "http://localhost:8082",
"OriginOneE": "http://localhost:8083"
}

.Net Core 处理跨域问题Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource的更多相关文章

  1. js跨域访问,No 'Access-Control-Allow-Origin' header is present on the requested resource

    js跨域访问提示错误:XMLHttpRequest cannot load http://...... No 'Access-Control-Allow-Origin' header is prese ...

  2. (转)AJax跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource

    在本地用ajax跨域访问请求时报错: No 'Access-Control-Allow-Origin' header is present on the requested resource. Ori ...

  3. 解决跨域No 'Access-Control-Allow-Origin' header is present on the requested resource.

    用angular发起http.get(),访问后端web API要数据,结果chrome报错:跨域了 Access to XMLHttpRequest at 'http://127.0.0.1:300 ...

  4. ajax跨域(No 'Access-Control-Allow-Origin' header is present on the requested resource)

    问题 在某域名下使用Ajax向另一个域名下的页面请求数据,会遇到跨域问题.另一个域名必须在response中添加 Access-Control-Allow-Origin 的header,才能让前者成功 ...

  5. java、ajax 跨域请求解决方案('Access-Control-Allow-Origin' header is present on the requested resource. Origin '请求源' is therefore not allowed access.)

      1.情景展示 ajax调取java服务器请求报错 报错信息如下: 'Access-Control-Allow-Origin' header is present on the requested ...

  6. No 'Access-Control-Allow-Origin' header is present on the requested resource——Web Api跨域问题

    最近使用C#写了一个简单的web api项目,在使用项目中的.cshtml文档测试的时候没有任何问题,但是在外部HBuilder上面编写.html通过Ajax调用web api路径时报错: No 'A ...

  7. 跨域问题解决----NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost:11000' is therfore not allowed access'

    NO 'Access-Control-Allow-Origin' header is present on the requested resource.Origin'http://localhost ...

  8. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' heade

    XMLHttpRequest cannot load http://10.164.153.37:8050/WebService/WebService.asmx/wsGetStreetData. Res ...

  9. As.net WebAPI CORS, 开启跨源访问,解决错误No 'Access-Control-Allow-Origin' header is present on the requested resource

    默认情况下ajax请求是有同源策略,限制了不同域请求的响应. 例子:http://localhost:23160/HtmlPage.html 请求不同源API http://localhost:228 ...

随机推荐

  1. K8S(02)管理核心资源的三种基本方法

    系列文章说明 本系列文章,可以基本算是 老男孩2019年王硕的K8S周末班课程 笔记,根据视频来看本笔记最好,否则有些地方会看不明白 需要视频可以联系我 管理k8s核心资源的三种基本方法: 目录 系列 ...

  2. Leetcode(35)-搜索插入位置

    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引.如果目标值不存在于数组中,返回它将会被按顺序插入的位置. 你可以假设数组中无重复元素. 这个题目很简单,因为它是给定的排序数组而且没有重 ...

  3. C++ part5

    为啥大三了课少了一点点,做作业的时间反而多了一大堆堆??? 关于protect 只能被本类或者子类的成员函数,或者友元函数访问. 友元函数: #include <iostream> #in ...

  4. 易漏的PEP8语法规范

    import后定义函数的话, 两个空白行. 函数参数内'='左右不加空格. 在写函数说明时, 三引号得是三个双引号.

  5. 如何在github实现 github pages (暨个人blog) websites for you and your projects.

    http://xgqfrms.github.io/xgqfrms/ 步骤如下: 1.GitHub Pages https://pages.github.com/ 2.Generate a site, ...

  6. Git常用命令速查表 & Git Basics & github : release 发布!

    Git常用命令速查表 & Git Basics  & github : release  发布! Git常用命令速查表: 1 1 1 1 1 http://git-scm.com/bo ...

  7. 图解 git workflow

    图解 git workflow 图解 git 工作流 git-flow https://www.git-tower.com/learn/git/ebook/cn/command-line/advanc ...

  8. Python Coding Interview

    Python Coding Interview Python Advanced Use enumerate() to iterate over both indices and values Debu ...

  9. SDK & 埋点 & user behavior tracker

    SDK & 埋点 & user behavior tracker 同一个 SDK ,根据不同的应用市场, 分别进行统计分析 ? https://www.umeng.com/ user ...

  10. svg rect to polygon points & points order bug

    svg rect to polygon points & points order bug https://codepen.io/xgqfrms/pen/vYOWjYr?editors=100 ...