0

I need to write an XML file to an Azure website folder under site root, with data pulled from the website's Azure SQL DB. This will be done on a recurring basis.

I have written a worker role which pulls the data and writes the file, however, it writes to a folder within the worker role folder structure using the below code. I am not sure how to specify and access the web folder path.

XmlTextWriter xml = new XmlTextWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "feed.xml"), Encoding.UTF8);

Both the worker role and the website are in the same VS project, and deployed to Azure.

Since both the website and the worker role are in their respective VM instances, maybe the WR cannot access the website - I am not completely sure, and would really appreciate any guidance.

Would a webjob be better suited for this? Can it connect to an Azure DB, and write to a folder within the site root? Appreciate any code examples.

Hassan K
  • 23
  • 4

1 Answers1

1

You wouldn't want to write a any single location as the server running your website is rather ethereal and can be taken offline and replaced at any time.

You should consider having your job generate the file and write it to Blob Storage and having your website read and serve the same file. Set up your site to treat the path to the file as a regular non-static route (this will let you keep the path /feeds/feed.xml) and the Action can read the XML file from your blob storage and serve it as the response.

Babak Naffas
  • 12,395
  • 3
  • 34
  • 49
  • Good point on availability, however a 3rd party service expects to reach my site and read that XML file i.e., www.site.com/feeds/feed.xml. Can the site serve it from this path if it is stored in the Blob Storage? I think it might be served as site.blob.core.windows.net/..../feed.xml. I need to be able to write to the site folder path despite the risk of site getting offline. – Hassan K Jul 06 '17 at 17:38
  • You can have your site stream the file. The answer is updated. – Babak Naffas Jul 06 '17 at 18:26
  • Great, I think that would work. This will entail configuring the domain name for the blob storage, and the link will be served. This article explains the process: https://learn.microsoft.com/en-us/azure/storage/storage-custom-domain-name – Hassan K Jul 07 '17 at 15:03