2016-12-15 131 views
3

我正在尝试设置CORS规则为我的存储帐户这里下配置CORS建议使用Azure的资源管理器工具:https://docs.microsoft.com/en-us/azure/app-service-api/app-service-api-cors-consume-javascript配置CORS使用Azure的资源管理器模板

通过增加财产CORS:

"resources": [ 
    { 
     "type": "Microsoft.Storage/storageAccounts", 
     "sku": { 
      "name": "Standard_RAGRS", 
      "tier": "Standard" 
     }, 
     "kind": "Storage", 
     "name": "[parameters('storageAccounts_teststoragejkjk_name')]", 
     "apiVersion": "2016-01-01", 
     "location": "westus", 
     "tags": {}, 
     "properties": { 
      "cors": {"allowedOrigins": ["*"]} 
     }, 
     "resources": [], 
     "dependsOn": [] 
    } 
] 

部署返回成功,我可以看到在Azure Portal中的活动日志下写入StorageAccount操作,但Cors规则不会添加到任何地方,并且当我从Azure下载模板时,它没有此“cors属性”。

我也试过手动添加科西嘉规则(我需要它只是我的斑点)和自动化脚本(包括deployment.ps)看起来还是一样的...

如何配置上的斑点一个Cors规则任何建议使用ARM模板存储?

回答

1

什么是您的部署客户端? 如果您使用Powershell来部署ARM(您可能是),为什么不使用Set-AzureStorageCORSRule

PS C:\>$CorsRules = (@{ 
[email protected]("x-ms-blob-content-type","x-ms-blob-content-disposition"); 
[email protected]("*"); 
MaxAgeInSeconds=30; 
[email protected]("Get","Connect")}, 
@{ 
[email protected]("http://www.fabrikam.com","http://www.contoso.com"); 
[email protected]("x-ms-meta-data*","x-ms-meta-customheader"); 
[email protected]("x-ms-meta-target*","x-ms-meta-customheader"); 
MaxAgeInSeconds=30; 
[email protected]("Put")}) 

PS C:\> Set-AzureStorageCORSRule -ServiceType Blob -CorsRules $CorsRules

+0

我觉得没有办法通过模板来做到这一点,所以我同意你的观点: – letlampa

+0

我用 设置-AzureStorageCORSRule -servicetype斑点-CorsRules $ CorsRules -Context $ StorageAccountContext – letlampa

+0

@letlampa很高兴帮助您:)别忘记标记问题为答案 – EvertonMc

1

我正在尝试设置CORS规则为我的存储帐户

我创建了一个类似ARM template创建一个存储帐户的资源,我发现,它似乎无法识别/接受CORS和其他属性(如我定义的val)除accountType属性。

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { }, 
    "variables": { }, 
    "resources": [ 
    { 
     "type": "Microsoft.Storage/storageAccounts", 
     "apiVersion": "2015-06-15", 
     "name": "[concat('storage', uniqueString(resourceGroup().id))]", 
     "location": "[resourceGroup().location]", 
     "properties": { 
     "accountType": "Standard_LRS", 
     "cors": { 
      "allowedHeaders": [ "*" ], 
      "allowedMethods": [ "get", "post", "put" ], 
      "allowedOrigins": [ "*" ], 
      "exposedHeaders": [ "*" ], 
      "maximumAge": 5 
     }, 
     "val": "123" 
     } 
    } 
    ], 
    "outputs": { } 
} 

此外,正如我们所知,我们可以配置一个Cors设定Azure存储服务(BLOB,表,队列和文件共享),它似乎并没有使我们的存储帐户配置一个Cors设定直接部署存储帐户模板。 enter image description here

0

存储账户CORS目前不是由存储资源提供支持,因此它无法通过模板来设置。正如弗雷德指出的那样,CORS只能通过data plane API在服务上设置。