首先是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 问题的更多相关文章

  1. 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 ...

  2. 解决跨域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 ...

  3. 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 ...

  4. .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 ...

  5. 解决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 ...

  6. 跨域问题解决----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 ...

  7. 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 ...

  8. 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 ...

  9. (转)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 ...

随机推荐

  1. jsp登录注册

    只帖源代码,,,,不讲解. 1.Login.jsp <%@ page language="java" import="java.util.*" pageE ...

  2. SpringBoot系列: 理解 Spring 的依赖注入(一)

    ==============================Spring 的依赖注入==============================对于 Spring 程序, Spring 框架为我们提供 ...

  3. 使用 CROSS APPLY 与 OUTER APPLY 连接查询

    Ø  前言 日常开发中遇到多表查询时,首先会想到 INNER JOIN 或 LEFT OUTER JOIN 等等,但是这两种查询有时候不能满足需求.比如,左表一条关联右表多条记录时,我需要控制右表的某 ...

  4. 求f(n)=[n/1]+[n/2]+---+[n/n]的值 简单杂题

    这种小题首先根据 n/1+n/2+n/3+--+n/n=nlogn+欧拉常数r 可以知道 1e12的范围也不会爆longlong,不需要写高精度(到现在都不会写) 再根据数据范围可知O(n)级别的暴力 ...

  5. 20155324王鸣宇安装虚拟机+初次学习Linux的感想20155324

    安装Linux系统 这是最后一次预备作业,但不是最后一次作业.当然要认真对待,在这个除旧迎新的日子里.认真的花了一个下午的时间专研学习了如何安装Linux系统.通过学习了基于VirtualBox虚拟机 ...

  6. 【译】第五篇 SQL Server安全架构和安全

    本篇文章是SQL Server安全系列的第五篇,详细内容请参考原文. 架构本质上是一个数据库对象,其他对象的一个容器,在复杂的数据库中它能够很容易的管理各组对象.架构具有重要的安全功能.在这一篇你会学 ...

  7. shell编程 之 echo命令和printf命令

    1 echo命令基本情况: echo显示普通字符:echo "i am studying shell"(有木有引号都可以) 支持转义字符:echo "\"hel ...

  8. 用多线程处理FTP上传

    在开发中遇到总站发送命令请求分站将某资源通过FTP上传过来,也就是总站提取分站的资源问题.并且总站实时可以获取已经提取了文件的大小的比例. 思路:1.首先分站要将文件大小告知总站 2.总站收到文件大小 ...

  9. 拦截RESTful API并做相应处理的方式

    ⒈使用Filter(过滤器) package cn.coreqi.security.filter; import org.springframework.stereotype.Component; i ...

  10. Python3-socket网络知识储备

    本文参考文章:http://www.cnblogs.com/linhaifeng/articles/6129246.html 计算机基础知识 客户端软件基于网络发送一条信息给服务端软件,流程是: 1. ...