有没有更好的方法可以从我的解决方案中的 html 文件中调用和获取我的电子邮件模板?
我正在从 Azure 函数项目和我的 ASP.Net MVC 项目中调用“AppDomain.CurrentDomain.BaseDirectory”来获取我的电子邮件模板的路径。(.html 文件)
但是从 Azure 函数发出的调用甚至没有返回解决方案中的路径!
简单来说,ASP.Net MVC 和 Azure 函数项目都在另一个名为 projectName.Services 的项目中调用 EmailService.cs 来构造电子邮件。
从这两个项目中,我都像这样调用 EmailService.cs
_emailService.CancelEventSendHostEmail(value1, someObject, anotherObject, "someMessage");
在'CancelEventSendHostEmail'中我正在做这样的事情
CancelEventSendHostEmail(/*incoming properties*/) {
var outerTemplateHtml = GetEmailTemplate("email-outer-body-template.html");
var specificTemplate= GetEmailTemplate("someTemplate.html");
// do some work to fill in values in the email
// send the email
}
现在 GetEmailTemplate 看起来像这样
public StringBuilder GetEmailTemplate(string templateName)
{
string htmlAsString
= File.ReadAllText(Path.Combine(Directory.GetParent(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).ToString()).ToString(),
@"Yogabandy2017.Services\EmailingTemplates", templateName));
return new StringBuilder(htmlAsString);
}
现在这可以很好地与 ASP.Net MVC 项目一起查找、获取和读取 HTML 模板文件作为字符串。EmailService.cs 从 ASP.Net MVC 项目中发现文件没有问题,但是当我从 Azure 函数调用“GetEmailTemaplate”时
AppDomain.CurrentDomain.BaseDirectory
path 返回不在项目或解决方案目录中的路径。
它返回一个看起来像这样的路径
C:\Users\chuckdawit\AppData\Local\AzureFunctionsTools\Releases\1.2.0\cli\
好像我在 asp.net mvc 应用程序中并且我在文本中读到“AppDomain.CurrentDomain.BaseDirectory”返回这样的路径
C:\Users\chuckdawit\Source\Workspaces\YogaBandy2017\YogaBandy2017\YogaBandy2017\
然后我可以在该项目的文件夹中搜索 html 电子邮件模板文件!