7

I need to refresh the contents when I upload a new content to CDN. When the content change, it's important that the updated data is immediately available. But CDN caches and it is not reflecting immediately.

I referred to site 'https://msdn.microsoft.com/en-us/library/mt634451.aspx' and tried implementing the same. However, when I try to hit it, I get authorzation error.

{ "error": { "code": "AuthenticationFailed", "message": "Authentication failed. The 'Authorization' header is missing." } }

But the article does not give info abt what needs to go into Authorization header. Can someone pls help me here, on how to construct this authorization header? Pls let me know if you need more details.

Note: I checked the SO post 'How do I force Azure CDN content to be purged or invalidated?' and it does give link to the msdn link(same as above), but not about the authorization header.

Community
  • 1
  • 1
csharpnewbie
  • 789
  • 2
  • 12
  • 33

1 Answers1

12

You are using the right API, but are not using the Azure API Authentication via your application. You can find details on how to authenticate your API request along with a reusable code sample here: Azure Authentication - Authenticating any Azure API Request in your Application

Alternatively, you can purge using the new portal web interface. Find the details on how to do that here: Purge an Azure CDN endpoint

Aman Sharma
  • 1,930
  • 1
  • 17
  • 31
  • thanks for the response. Yes. I know how to purge them manually via the portal. I want to automate it via c# code. I looked into the code shared. Can you pls give more info abt TenanatID, ClientID and password etc, where to get these info from azure portal. – csharpnewbie May 03 '16 at 17:08
  • 1
    Sure! Just download the code from my GitHub repo here: [Azure Authentication](https://github.com/HarvestingClouds/AzureAuthentication). Include the configurations from the App.config file and include the helper class in your project. Then follow the instructions from the comments in the header of the method of authentication you want to use. The pre-reqs to get the Tenant ID and Client ID are here: [Authenticating w/ ARM](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/). Relevant section is in the comments for each of the method. – Aman Sharma May 03 '16 at 17:13
  • @csharpnewbie If this solved your problem please mark this as an answer by clicking on the tick mark below the arrows beside my answer. Let us know if you need more help. – Aman Sharma May 03 '16 at 22:26