我正在通过XHR存储我的蓝宝石上的json blob.在尝试加载这些Blob时,我收到此错误:
XMLHttpRequest无法加载 http://myazureaccount.blob.core.windows.net/myjsoncontainer/myblob.json?json. Access-Control-Allow-Origin不允许Origin http://localhost.
XMLHttpRequest无法加载 http://myazureaccount.blob.core.windows.net/myjsoncontainer/myblob.json?json. Access-Control-Allow-Origin不允许Origin http://localhost.
有没有办法设置由天蓝色返回的blob的Access-Control-Allow-Origin标题?
Windows Azure存储在2013年11月26日添加了CORS支持:
Cross-Origin Resource Sharing (CORS) Support for the Windows Azure Storage Services.更多细节和C#/ JavaScript示例 –
Windows Azure Storage: Introducing CORS.
CORS选项可以使用可从NuGet获得的Windows.Azure.Storage客户端库3.0.1.0或更高版本的存储帐户设置,使用类似于以下伪代码的内容:
var storageAccount = CloudStorageAccount.Parse( "DefaultEndpointsProtocol=https;AccountName=ABC;AccountKey=XYZ"); var blobClient = storageAccount.CreateCloudBlobClient(); var serviceProperties = blobClient.GetServiceProperties(); serviceProperties.Cors.CorsRules.Clear(); serviceProperties.Cors.CorsRules.Add(new CorsRule() { AllowedHeaders = { "..." },AllowedMethods = CorsHttpMethods.Get | CorsHttpMethods.Head,AllowedOrigins = { "..." },ExposedHeaders = { "..." },MaxAgeInSeconds = 600 }); blobClient.SetServiceProperties(serviceProperties);