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

标签 azure asp.net-core azure-web-app-service hangfire

我有一个 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/

相关文章:

asp.net-core - VS 2019 自定义 ASP.NET Core 项目模板

azure - 更新已扩展的应用服务中的应用程序

asp.net-mvc - Azure 文件存储/索引解决方案

database - 通过现有数据库还原 Azure SQL DB 以维护备份历史记录

Azure服务总线队列: Load Balancing Capability

asp.net-core - 如何在不访问请求的情况下获取基本网址

c# - 使用 github 操作进行部署时更改 appsettings 中的变量

azure - 谁更快? AppFabric 缓存还是 Memcached?

c# - 无效的 .afpkg 文件 - 如何查找更多信息?

asp.net-core - 在 SignalR 的集线器外访问 Context.ConnectionID