简体   繁体   中英

How to write a file to an Azure website folder from a webjob or worker role

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM