为什么我不能进行跨起源请求在IIS托管的API

为什么我不能进行跨起源请求在IIS托管的API

本文介绍了为什么我不能进行跨起源请求在IIS托管的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET的WebAPI应用程序中使用IISEx preSS,让我接受来自任何域的请求本地运行。我做这个使用 DelegatingHandler 一个类似于提供的一个的。

I have an ASP.NET WebApi application running locally using IISExpress that allows me to accept requests from any domain. I am doing this using a DelegatingHandler similar to the one provided one this blob post.

这个局部然而完美上传到Azure的网站运行后,我得到的典型'原产地的http://本地主机:8080不会被允许访问控制允许来源的Chrome下。

Locally this runs perfectly however after uploading to an Azure Website, I get the typical 'Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.' under Chrome.

我已经尝试通过添加跟踪语句进入处理程序没有输出调试这个和它看起来像SendAsync永远不会被执行,仿佛IIS正在响应OPTIONS请求,而不是将它传递给我的应用程序。

I've tried to debug this by adding trace statements into the Handler with no output and it seems like SendAsync is never being executed, almost as if IIS is responding to the OPTIONS request instead of passing it on to my application.

有没有人遇到过类似的事情从开发去生产?

Has anyone come across anything similar going from development to production?

推荐答案

IIS(包括一个在您的Azure网站)有一个默认选项处理程序。您需要在Web.config中删除它。它回答OPTIONS调用之前,消息处理程序有机会作出回应。

IIS (including the one in your Azure web site) has a default OPTIONS handler. You will need to remove it in Web.config. It answers the OPTIONS call before your message handler has an opportunity to respond.

<configuration>
  ...
  <system.webServer>
    <handlers>
      <remove name="OPTIONSVerbHandler" />
      ...
    </handlers>
  </system.webServer>
</configuration>

这篇关于为什么我不能进行跨起源请求在IIS托管的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 00:34