2

Is there any way, with any of the .Net Azure libraries to check if a resource exists on the CDN. I can check if a blob exists but haven't come across anything that will check if it also exists on the CDN

1 Answers1

3

Imagine that your BLOB URL is :

http://foo.blob.core.windows.net/cdn/test.png

and that your CDN endpoint is bar.vo.msecnd.net

Just do an HTTP HEAD request on http://bar.vo.msecnd.net/cdn/test.png to see if the file exists.

To paraphrase the code submitted in this answer

HttpWebResponse response = null;
var request = (HttpWebRequest)WebRequest.Create("http://bar.vo.msecnd.net/cdn/test.png");
request.Method = "HEAD";


try
{
    response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
    /* do something here */
}
finally
{
    // Don't forget to close your response.
    if (response != null)
    {
        response.Close()
    }
}
Community
  • 1
  • 1
qux
  • 1,155
  • 7
  • 17