在我的web.config中,我想为access-control-allow-origin指令指定多个域.我不想用*.我试过这个语法:
<add name="Access-Control-Allow-Origin" value="http://localhost:1506, http://localhost:1502" />
Run Code Online (Sandbox Code Playgroud)
这个
<add name="Access-Control-Allow-Origin" value="http://localhost:1506 http://localhost:1502" />
Run Code Online (Sandbox Code Playgroud)
这个
<add name="Access-Control-Allow-Origin" value="http://localhost:1506; http://localhost:1502" />
Run Code Online (Sandbox Code Playgroud)
还有这个
<add name="Access-Control-Allow-Origin" value="http://localhost:1506" />
<add name="Access-Control-Allow-Origin" value="http://localhost:1502" />
Run Code Online (Sandbox Code Playgroud)
但它们都不起作用.什么是正确的语法?
我创建了一个phonegap应用程序,我正在调用WCF服务,该服务位于nopCommerce插件中.
我在发送api请求时遇到以下错误:
跨源请求已阻止:同源策略禁止在http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData上读取远程资源.(原因:CORS预检频道没有成功).
跨源请求已阻止:同源策略禁止在http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData上读取远程资源.(原因:CORS请求失败).
使用Ajax进行API调用
$.ajax({
crossDomain: true,
type: "POST",
contentType: "application/json",
async: false,
url: "http://testwebsite.com/Plugins/NopRestApi/RemoteService/WebService.svc/GetData",
data: "{storeId:" + storeId + ", languageId:" + languageId + ", customerId:" + customerId + "}",
//data: { storeId: storeId, languageId: languageId, customerId: customerId },
dataType: 'json',
//jsonp: false,
success: function (data) {
alert(data.d);
},
error: function (xhr, textStatus, error) {
alert("Error! " + error);
}
});
Run Code Online (Sandbox Code Playgroud)
我通过谷歌的一些研究在我的Web.config文件中添加了以下内容.
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol> …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用 Angular 2 和 Web API 技术。我正在通过 $http 调用从 Angular 调用 Web API 服务方法。
实际上API方法是从数据库中读取数据并执行大量逻辑来将数据转换为UI实体类(其中有很多代码和循环,所以我不会在这里发布它们)。
问题是当我调用 API 方法时收到 502 Bad get way 错误。
我发现这个问题是因为它是一个性能问题。当数据量较小时,它对我来说工作得很好。但如果数据量很大,那么我会收到此错误。
注意:我已经检查了数据库查询。它工作正常并且返回数据非常快。
我使用计时器来检查API方法的响应时间
响应时间结果如下:
如果数据量较小:00.00:898767 (hh:mm:ss)
如果数据量很大:00:06:654389 (hh:mm:ss)
如果方法响应时间超过 2 分钟,那么只有我收到 bad get way 错误。否则该方法执行成功,没有任何错误。
我尝试过增加executionTimeout=9000 我web config.也尝试过使用不同的秒数executionTimeout.
这是我完整的网络配置代码
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.web>
<authentication mode="Windows"></authentication>
<authorization>
<deny users="?" />
</authorization>
<httpRuntime …Run Code Online (Sandbox Code Playgroud) asp.net ×2
web-config ×2
angular ×1
c# ×1
cors ×1
cross-domain ×1
iis ×1
nopcommerce ×1
wcf ×1