0

我需要为Azure容器创建Azure CDN端点。我正在使用下面的代码来这样做。为天蓝色容器创建天蓝色cdn端点

Endpoint endpoint = new Endpoint() { 
       IsHttpAllowed = true, 
       IsHttpsAllowed = true, 
       Location = this.config.ResourceLocation, 
       Origins = new List<DeepCreatedOrigin> { new DeepCreatedOrigin(containerName, string.Format(STORAGE_URL, storageAccountName)) }, 
       OriginPath = "/" + containerName,      
      }; 
      await this.cdnManagementClient.Endpoints.CreateAsync(this.config.ResourceGroupName, storageAccountName, containerName, endpoint); 

我提供的所有信息都是正确的,Endpoint正在成功创建。但是当我尝试访问它里面的任何blob。它给出了一个InvalidUrl错误。

然而奇怪的是如果我通过门户使用相同的值创建相同的端点,我可以访问和下载blob。

任何人请让我知道我在我的代码中做错了什么?我需要传递任何额外的参数吗?

回答

1

据我所知,如果你想在代码中创建一个存储CDN,你需要设置OriginHostHeader的值作为你的存储帐户的URL。

更多细节,你可以参考下面的代码:

// Create CDN client 
      CdnManagementClient cdn = new CdnManagementClient(new TokenCredentials(token)) 
      { SubscriptionId = subscriptionId }; 
      //ListProfilesAndEndpoints(cdn); 
      Endpoint e1 = new Endpoint() 
      { 
       // OptimizationType = "storage", 
       Origins = new List<DeepCreatedOrigin>() { new DeepCreatedOrigin("{yourstoragename}-blob-core-windows-net", "{yourstoragename}.blob.core.windows.net") }, 
       OriginHostHeader = "{yourstoragename}.blob.core.windows.net", 
       IsHttpAllowed = true, 
       IsHttpsAllowed = true, 
       [email protected]"/foo2", 
       Location = "EastAsia" 
     }; 

     cdn.Endpoints.Create(resourcegroup, profilename, enpointname, e1); 

此外,我建议你可以生成SAS令牌通过网址直接访问BLOB文件。

+0

嘿白兰度,非常感谢。似乎我的问题得到解决后,我传递了一个额外的参数OriginAuthHeader。我将此标记为答案。 虽然,你能帮我一个忙吗?你能否提供我这个信息的来源,他们提到这个参数必须在创建Endpoint的时候?再次感谢。 –

+0

我很抱歉,我无法给你正确的信息。我根据门户的添加enpoit对话框编写此参数。它需要OriginHostHeader参数,所以我测试它在我身边。 –