栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Portal的Azure BLOB存储中设置CORS?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Portal的Azure BLOB存储中设置CORS?

更新:
在回答此问题时,Azure门户没有此功能。现在按此处概述进行操作。下面概述了添加UI之前执行此操作的方法。

如何在Portal的Azure BLOB存储中配置CORS?

如果愿意,可以始终以编程方式设置BORS存储的CORS规则。如果您使用的是.Net Storage
Client库,请从存储团队中查看此博客文章:http :
//blogs.msdn.com/b/windowsazurestorage/archive/2014/02/03/windows-azure-
storage-introducing-
cors.aspx。用于从该博客文章中设置CORS设置的代码:

private static void InitializeCors(){     // CORS should be enabled once at service startup     // Given a BlobClient, download the current Service Properties      ServiceProperties blobServiceProperties = BlobClient.GetServiceProperties();     ServiceProperties tableServiceProperties = TableClient.GetServiceProperties();     // Enable and Configure CORS     ConfigureCors(blobServiceProperties);     ConfigureCors(tableServiceProperties);     // Commit the CORS changes into the Service Properties     BlobClient.SetServiceProperties(blobServiceProperties);     TableClient.SetServiceProperties(tableServiceProperties);}private static void ConfigureCors(ServiceProperties serviceProperties){    serviceProperties.Cors = new CorsProperties();    serviceProperties.Cors.CorsRules.Add(new CorsRule()    {        AllowedHeaders = new List<string>() { "*" },        AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post,        AllowedOrigins = new List<string>() { "*" },        ExposedHeaders = new List<string>() { "*" },        MaxAgeInSeconds = 1800 // 30 minutes     });}

如果您正在寻找执行此操作的工具,则一些存储浏览器支持配置CORS-Azure存储资源管理器,Cerebrata Azure ManagementStudio,Cloud Portam(公开-我正在构建Cloud Portam实用程序)。

正确配置CORS之后,您可以使用Rory的答案中提到的代码从blob存储中下载文件。正如Rory所说,您不必在客户端做任何特殊的事情。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388365.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号