我添加了这条规则:
var corsRule = new CorsRule()
{
AllowedHeaders = new List<string> { "x-ms-*", "content-type", "accept" },
AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Options,//Since we'll only be calling Put Blob, let's just allow PUT verb
AllowedOrigins = new List<string> { "https://localhost:44309" },//This is the URL of our application.
MaxAgeInSeconds = 1 * 60 * 60,//Let the browswer cache it for an hour
};
执行
之后的chrome控制台 $.ajax(sasUrl + '&comp=list', {
type: 'GET',
crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob');
},
}).done((data) => console.log(data));
这是印刷品:
403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:44309' is therefore not allowed access.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:44309' is therefore not allowed access.
答案 0 :(得分:0)
请尝试删除请求中的x-ms-blob-type
请求标头。所以你的ajax代码应该是:
$.ajax(sasUrl + '&comp=list', {
type: 'GET',
crossDomain: true,
beforeSend: function (xhr) {
//xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob');
},
}).done((data) => console.log(data));