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
Asked
Active
Viewed 1,160 times
1 Answers
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()
}
}
-
But won't this lead to the CDN fetching the image ? – Erik Oppedijk Apr 16 '16 at 12:04
-
No, because it's HEAD not GET, ao it's not fethcing the img respone body – Neil Thompson Apr 16 '16 at 16:59