简体   繁体   English

CORS访问控制允许起源头不存在

[英]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.

相关问题 CORS错误:不存在“ Access-Control-Allow-Origin”标头 - CORS Error : No 'Access-Control-Allow-Origin' header is present CORS“没有&#39;Access-Control-Allow-Origin&#39;标题存在”但是有 - CORS “No 'Access-Control-Allow-Origin' header is present” yet there is 带有Access-Control-Allow-Origin标头的Jquery + CORS +基本身份验证:所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Jquery + CORS+ Basic Auth with Access-Control-Allow-Origin header: No 'Access-Control-Allow-Origin' header is present on the requested resource SAP OData 服务中的 CORS 问题 - 不存在“Access-Control-Allow-Origin”标头 - CORS Issue in SAP OData Service - No 'Access-Control-Allow-Origin' Header Is Present CORS问题:获取错误“No'Access-Control-Allow-Origin'标题存在”实际存在时 - CORS issue: Getting error “No 'Access-Control-Allow-Origin' header is present” when it actually is CORS 问题 - 请求的资源上不存在“Access-Control-Allow-Origin”header - CORS issue - No 'Access-Control-Allow-Origin' header is present on the requested resource (原因:CORS标头“ Access-Control-Allow-Origin”缺失) - (Reason: CORS header ‘Access-Control-Allow-Origin’ missing) 缺少 CORS 标头“Access-Control-Allow-Origin” - CORS header 'Access-Control-Allow-Origin' missing CORS 策略已阻止从原点 '' 在 '' 访问 XMLHttpRequest:没有 'Access-Control-Allow-Origin' header 存在于请求的 - Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested Apache:缺少CORS标题“Access-Control-Allow-Origin” - Apache : CORS header 'Access-Control-Allow-Origin' missing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM