在天蓝色中部署时无法创建绝对文件路径

cannot create absolute file path when deploying in azure

我正在尝试创建一个聊天机器人,然后将其部署到我的 azure 帐户中,问题是我有时需要 post 讨论中的文档作为响应,但绝对文件路径没有当 bot 在 azure 中 depolyed 时工作,但它在我的本地主机上工作。

var imagePath = HttpContext.Current.Server.MapPath("~/Files/mutuelle.pdf");

这是生成文件路径的代码。在天蓝色中部署时,link 到文件是:

https://*******.azurewebsites.net/dev/wwwroot/Files/mutuelle.pdf

我想问题是 imagePath 变量只是

https://*******.azurewebsites.net/Files/mutuelle.pdf.

所以我在 azure (dev/wwwroot/) 中生成绝对文件路径时遇到问题。 有人可以告诉我解决方案吗?

就我个人而言,我使用以下命令通过相对路径访问我在 Azure 上的文件,我的文件位于我的 VS 项目的 Credential 文件夹中,一切正常。

System.Web.HttpContext.Current.Server.MapPath("..\Credential\XXX.json");

您可以在您的项目中创建一个文件夹,例如 /Contents,并将您需要发送的所有文件保存在该文件夹中。

部署到 Azure 后,您可以将托管的 url 添加到 web.config 文件中,作为

<appSettings>      
<add key="HostedUrl" value="https://**.azurewebsites.net/Content/" />
<appSettings>

然后在对话框中您可以将图片路径设置为:

private static string contentUrl = ConfigurationManager.AppSettings["HostedUrl"];    
var imageUrl = contentUrl + "imageName.png";