我有下面的代码。
WCF REST方法
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Account")]
[OperationContract]
string GetUniqueLoginId();客户端调用
$.ajax({
type: "GET",
url: serviceURL + 'Account',
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: app.onGetUniqueId,
error: app.onAjaxError
});当我使用IE (11)时,它通过返回唯一的id来完美地工作。但是,当我使用铬时,它会给出以下错误。
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5553' is therefore not allowed access.如何解决这个问题?任何帮助都将不胜感激。
发布于 2013-12-14 20:30:25
这意味着您请求的WCF服务与调用它的应用程序不同,因此受"Same Origin policy" .You的限制,必须使用JSONP(服务必须支持jsonp)或CORS (服务器端应该添加允许您的来源的CORS标头)。
发布于 2015-04-17 19:15:58
通过在web配置文件中添加以下配置,您需要在IIS或IIS Express上托管的服务上启用CORS。
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
...
通过将其设置为*,我们允许来自任何来源的请求访问服务。
https://stackoverflow.com/questions/20259876
复制相似问题