lss*_*lss 5 c# azure asp.net-core
我有一个在Azure上运行的ASP.NET Core应用程序。该应用程序以明文和HTML格式发送各种电子邮件。我在文件夹中创建了一个子Resources
文件夹,名为EmailTemplates
,用于存储所有HTML和TXT模板。示例路径可能是:
\src\WebProject\Resources\EmailTemplates\Welcome.html
我通过EmailService.cs
以下方式访问班级中的文件:
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "EmailTemplates", "Welcome.html");
var htmlTemplate = await File.ReadAllTextAsync(filePath);
Run Code Online (Sandbox Code Playgroud)
当在IIS和Kestrel上的本地环境上运行时,这非常有用。但是,当部署到Azure时,我收到一条IO错误消息:
System.IO.DirectoryNotFoundException
An unhandled exception has occurred: Could not find a part of the path 'D:\home\site\wwwroot\Resources\EmailTemplates\Welcome.html'.
Run Code Online (Sandbox Code Playgroud)
我在StackOverflow上发现了类似的问题,但答案已经接近6年了。我不确定,自从Azure在过去几年中发生重大变化以来,它是否仍然适用。我也在看官方文档(1) (2),但没有发现关于Azure的任何特别之处。
在ASP.NET Core和Azure中存储和检索电子邮件模板(和其他静态文件)的正确方法是什么?
归档时间: |
|
查看次数: |
821 次 |
最近记录: |