I have an ASP.NET Core API app which runs some background processes via HangFire. One of the process includes writing a csv file onto the wwwroot folder as following:
public async Task Work(PerformContext context)
{
var latestLikes = await this.likeRepository
.All()
.Select(l => new LatestLikesServiceModel
{
UserId = l.UserId,
BeatId = l.BeatId,
})
.ToListAsync();
var modelPath = this.webHostEnvironment.ContentRootPath + "\\dataModel.csv";
using (var writer = new StreamWriter(modelPath))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(latestLikes);
}
}
In localhost it works perfectly, but when I deploy it in azure the HangFire log returns:
"System.UnauthorizedAccessException","ExceptionMessage":"Access to the path 'C:\home\site\wwwroot\dataModel.csv' is denied."
How can I resolve this issue?
D:\home\site\wwwroot\dataModel.csv
. – Jason Pan