gpt4 book ai didi

azure - .NET Core 应用程序中的 "Access to the path ' C :\\home\\site\\wwwroot\\dataModel. csv ' is denied.",部署在 Azure 中

转载 作者:行者123 更新时间:2023-12-03 01:24:57 29 4
gpt4 key购买 nike

我有一个 ASP.NET Core API 应用程序,它通过 HangFire 运行一些后台进程。其中一个过程包括将 csv 文件写入 wwwroot 文件夹,如下所示:

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);
}
}

在本地主机中它工作得很好,但是当我在 azure 中部署它时,HangFire 日志返回:"System.UnauthorizedAccessException","ExceptionMessage":"访问路径 'C:\home\site\wwwroot\dataModel.csv' 被拒绝。"
我该如何解决这个问题?

最佳答案

经过一周的研究,我终于找到了解决方案
我应该提到我使用 Azure DevOps 进行 CI 和 CD。
默认情况下,azure应用程序服务被部署为zip(这减少了对文件系统的直接访问)我所要做的是将部署方法更改为Web部署( Additional Deployment Options ),我终于可以访问该文件系统。更多描述信息请引用:
https://tomasherceg.com/blog/post/azure-app-service-cannot-create-directories-and-write-to-filesystem-when-deployed-using-azure-devops#comments

关于azure - .NET Core 应用程序中的 "Access to the path ' C :\\home\\site\\wwwroot\\dataModel. csv ' is denied.",部署在 Azure 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66813183/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com