请注意,这个问题是专门针对Dynamics的。我希望有一种专有的功能来扩展或取代普通的web开发。因此,这个问题并不是一个重复的问题,尽管一旦人们看到"CORS“和”另一只鸭子询问CORS.“,它可能会显得如此.(意为打字)。
我试图打电话给CRM的外部消息,当然,我遇到了CORS的问题。现在,我对调用指向的服务器端几乎没有控制,所以我想知道是否有可能从客户端绕过它。
最好的解决方案是,如果服务器开发人员允许来自不同域的调用,但是他们可能不会这么做。那么,除了编写一个针对CRM 和调用的自定义服务层之外,我还有什么选择?
nag如下所示(当然,从URL行调用执行得非常好)。
跨源请求被阻止:相同的原产地策略不允许在=1415714629958上读取远程资源。可以通过将资源移动到相同的域或启用CORS来解决这个问题。
发布于 2017-07-19 13:47:18
这是一个老问题,但我在CRM2011(和IIS7.0)编辑web.config时解决了这个问题。
我已经将CORS头添加到IIS响应中。
添加基本标头
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="Origin, X-HTTP-Method, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>[..]添加规则
安装Url重写并添加以下规则
<rewrite>
<rules>
[..]
<!-- This rule allow the prefligh request to be authenticated, otherwise raise the 401 error, required ONLY if you use POST, for GET only is not necessary -->
<rule name="CORS Preflight Anonymous Authentication" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^OPTIONS$" />
</conditions>
<action type="CustomResponse" statusCode="200" statusReason="Preflight" statusDescription="Preflight" />
</rule>
[..]
</rules>
<outboundRules>
<clear />
<rule name="AddCORSHeaders">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<!-- This add the Access-Control-Allow-Origin if the pattern match the request url -->
<add input="{HTTP_ORIGIN}" pattern="(http(s)?://((.+\.)?domain1\.lan|(.+\.)?mydomain\.com|(.+\.)?otherdomain\.com))" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
</outboundRules>
</rewrite>https://stackoverflow.com/questions/26873822
复制相似问题