[英]Cors access-control-allow-origin header not present
I have an owin/katana project. 我有一个owin / katana项目。 So no IIS.
因此没有IIS。
public void Configuration(IAppBuilder app)
{
app.Run(context =>
{
context.Response.ContentType = "application/json";
context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
// etc.
}
and client side this jQuery: 和客户端这jQuery:
$.ajax({
dataType: "json",
url: labelPrintLoc,
success: function (msg) {
console.log(msg);
if (msg === "Done")
alert("Printed!");
else {
alert("Error, check the log on the server!");
}
},
error: function(a, b, c) {
console.log(a);
console.log(b);
console.log(c);
}
});
XMLHttpRequest cannot load http://xxxx:9000 No 'Access-Control-Allow-Origin' header is present on the requested resource.
XMLHttpRequest无法加载http:// xxxx:9000请求的资源上不存在“ Access-Control-Allow-Origin”标头。 Origin http://yyy is therfore not allowed access.
因此,不允许访问起点http:// yyy 。
I have seen this similar question https://stackoverflow.com/a/6516634/169714 but there is no AppendHeader
method. 我已经看到了类似的问题https://stackoverflow.com/a/6516634/169714,但是没有
AppendHeader
方法。 I thought that the *
gave everyone access? 我以为
*
允许所有人访问?
edit will try option 3 from this url: https://researchaholic.com/2015/04/28/how-to-fix-no-access-control-allow-origin-header-in-asp-net-webapi/ 编辑将尝试从该URL尝试选项3: https : //researchaholic.com/2015/04/28/how-to-fix-no-access-control-allow-origin-header-in-asp-net-webapi/
edit2 adding the nuget and this line app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
edit2添加nuget和该行
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
and remove the line with headers.add gives me a 500 error, because the origin was already set. 并删除带有headers.add的行,因为原点已设置,所以出现500错误。
This is a webserver Problem. 这是一个网络服务器问题。
Add this to your configuration file. 将此添加到您的配置文件。 It corresponds to apaches
Access-Control-Allow-Origin "*"
. 它对应于补发
Access-Control-Allow-Origin "*"
。
<appSettings>
<add key="cors:Origins" value="*" />
<add key="cors:Headers" value="*" />
<add key="cors:Methods" value="GET, POST, OPTIONS, PUT, DELETE" />
</appSettings>
This will enable cross origin requests for a Katana/Owin setup. 这将启用针对Katana / Owin设置的跨源请求。
This article could be useful too. 本文也可能有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.