I implemented VirtualPathProvider to return theme files (images, css) for an Azure website with an Azure CDN. It works fine, except for one thing: files that come from the CDN have a caching property set to "private" and therefore are never cached.
Actual drops have their properties correctly, and if I get access to it with direct URLs (i.e. not via VPP), then cache management will be correct.
The problem is the Open () method of the VirtualFile class, which I have to implement in order to return the file as a stream?
public override Stream Open() { CloudBlobClient client = new CloudBlobClient(cdnURL); CloudBlob blob = client.GetBlobReference(blobURL); blob.FetchAttributes(); MemoryStream stream = new MemoryStream(); BlobRequestOptions options = new BlobRequestOptions(); options.BlobListingDetails = BlobListingDetails.Metadata; blob.DownloadToStream(stream,options); stream.Seek(0, SeekOrigin.Begin); return stream; }
Search on this subject, and I believe that most people have a problem in a different way - i.e. files are cached when they do not want them to be. However, none of the examples I can find refers to a file from a different URL. It seems that they all use databases or just different physical paths.
source share