Webapi 跨域 解决解决错误No 'Access-Control-Allow-Origin' header is present on the requested resource 问题
首先是web端(http://localhost:53784) 请求 api(http://localhost:81/api/)时出现错误信息:
查看控制台会发现错误:XMLHttpRequest cannot load http://localhost:81/api/. No ‘Access-Control-Allow-Origin‘ header is present on the requested resource. Origin ‘http://localhost:53784‘ is therefore not allowed access.
这时会发现并没有阻止请求的发送,而是阻止了不同源请求的响应。也就是说请求没有问题,问题出在了响应。那么如何对指定的源开放访问???
第一步:首先在工具里面打开输入;Install-Package Microsoft.AspNet.WebApi.Cors 回车。
第二步:等第一步完成后 打开App_Start/WebApiConfig.cs. 添加一下代码: config.EnableCors();
第三步:在需要访问的Controlls上面加这样的属性: [EnableCors(origins: "http://localhost:53784", headers: "*", methods: "*")]
现在可以再试试看看效果。如果可以请给个赞 希望帮助到更多的人。
Webapi 跨域 解决解决错误No 'Access-Control-Allow-Origin' header is present on the requested resource 问题的更多相关文章
- 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 ...
- 解决跨域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 ...
- 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 ...
- .Net Core 处理跨域问题Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
网页请求报错: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Or ...
- 解决Tomcat错误信息:No 'Access-Control-Allow-Origin' header is present on the requested resource | Solving Tomcat Error: No 'Access-Control-Allow-Origin' header is present on the requested resource
最近在使用GeoServer调用Vector Tile服务时,经常会显示不出来结果.打开浏览器调试台,发现报No 'Access-Control-Allow-Origin' header is pre ...
- 跨域问题解决----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 ...
- WCF REST开启Cors 解决 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 405.
现象: 编写了REST接口: [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(UriTemp ...
- 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 ...
- (转)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 ...
随机推荐
- 26. SpringBoot 初识缓存及 SimpleCacheConfiguration源码解析
1.引入一下starter: web.cache.Mybatis.MySQL @MapperScan("com.everjiankang.cache.dao") @SpringBo ...
- Mark Text - 下一代所见即所得的Markdown编辑器
Mark Text 所输及所见,摒弃了众多 markdown 编辑器左边写作右边预览的写作方式,巧妙的将编辑和预览融为一体.snabbdom 作为 Mark Text 的渲染引擎,保证了极速渲染编辑页 ...
- C#基础_MD5
MD5加密 1创建Md5 2.开始加密,需要将字符转换为字节数组 3.返回一个加密好的字节数组 4.将字节数组中每个元素按照指定的编码格式解析成字符串 1 static void Main(strin ...
- vs不自动退出控制台程序的办法
1.在主函数rerurn 前加上getchar();即可. 2.ctrl+F5;
- springboot12-zuul
Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门,提供动态路由,监控,弹性,安全等的边缘服务 所有请求都经过网关(API Gateway)zuul,然后转发到各个子服 ...
- ThinkPHP5.0.21&5.1.* 代码执行和命令执行漏洞利用
ThinkPHP5.0.21&5.1.* 代码执行和命令执行漏洞利用 ThinkPHP5.0.21&5.1.* exploit code execution and command ...
- VUE项目安装
连接转载:https://www.cnblogs.com/Colwill-Blog/p/6682091.html 刚刚开始学习Vue.js.今天分享一下我的Vue项目安装过程. 我是windows系统 ...
- python后端将svc文件数据读入数据库具体实现
如何用python将svc文件的数据读入到MySQL数据库里,在此直接上代码了,感兴趣的朋友可以贴代码测试: import pandas as pd import os from sqlalchemy ...
- 【深入分析Java Web技术内幕】2、深入分析Java I/O的工作机制
Java的I/O类库的基本架构 基于字节操作的IO接口:InputStream.OutputStream 基于字符操作的IO接口:Writer.Reader 基于磁盘操作的IO接口:File 基于网络 ...
- 黑客游戏_www.fbisb.com 通关过程
黑客游戏_www.fbisb.com 首先这个游戏是非常非常基础的. 输入网址 http://www.fbisb.com/youxi/ 来到第一关 ctrl+u查看源码,注意右键不行,因为这段js代码 ...