Asp.net core 在生产环境中尝试通过.net core 3.X中的相对路径读取文件时出错

Asp.net core 在生产环境中尝试通过.net core 3.X中的相对路径读取文件时出错,asp.net-core,path,filepath,getdirectories,path-combine,Asp.net Core,Path,Filepath,Getdirectories,Path Combine,当我在localhost中运行我的项目时,我能够找到文件并进一步处理它。这是通过这行代码实现的 path=path.Combine(Directory.GetCurrentDirectory(),“EmailTemplates\\SuccessOrderWindows10.html”); 我能够得到完整的相对路径C:\etc\etc\etc。。但是当我把这段代码推到生产阶段,当它达到这个阶段时,它抛出了一个错误 Error One or more occurred. (Could not fi

当我在localhost中运行我的项目时,我能够找到文件并进一步处理它。这是通过这行代码实现的

path=path.Combine(Directory.GetCurrentDirectory(),“EmailTemplates\\SuccessOrderWindows10.html”);
我能够得到完整的相对路径C:\etc\etc\etc。。但是当我把这段代码推到生产阶段,当它达到这个阶段时,它抛出了一个错误

Error One or more occurred. (Could not find a part of the path 'h:\root\home\username\www\sitename\EmailTemplates\SuccessOrderWindows10.html'.)

我做错了什么?我是否必须选择文件并将其设置为内容,以便将其包含在生成中?

Directory.GetCurrentDirectory将获取应用程序的当前工作目录。当您将代码推送到生产时,您将更改当前工作目录,从而更改文件的相对路径,因此,生产时需要将文件放入新路径
h:\root\home\username\www\sitename\EmailTemplates\SuccessOrderWindows10.html。或者可以使用绝对路径