简体   繁体   English

Windows Azure访问App_Data

[英]Windows Azure access App_Data

I need to write file to App_Data folder in Asp.Net MVC project. 我需要将文件写入Asp.Net MVC项目中的App_Data文件夹。 It works locally, but when I deployed it to Windows Azure I received error like: 它在本地工作,但当我将其部署到Windows Azure时,我收到如下错误:

Could not find a part of the path 'C:\DWASFiles\Sites\codehint\VirtualDirectory0\site\wwwroot\App_Data\text.txt'.

I need to use third party library that have to get read/write access to App_Data folder. 我需要使用必须获得对App_Data文件夹的读/写访问权限的第三方库。

I use code like this: 我使用这样的代码:

var path = Server.MapPath("~/App_Data/text.txt");
using (var file = new StreamWriter(path))
{
   file.Write("test line");
   file.Flush();
}

If App_Data folder was empty, it was not deployed, so you need to create it 如果App_Data文件夹为空,则表示未部署,因此您需要创建它

see my reply here 看到我的回答这里

如果您使用的是VS2017并右键单击App_Data文件夹,则可以选择发布文件夹。

I had the same problem, and I solved it by creating the initial file in my solution's App_Data folder, and then I added the file to the solution by right-clicking on App_Start and choosing Add->Existing Item... 我有同样的问题,我通过在我的解决方案的App_Data文件夹中创建初始文件来解决它,然后我通过右键单击App_Start并选择Add-> Existing Item ...将文件添加到解决方案中...

在此输入图像描述

It needed to be added to the solution in order to be published. 需要将其添加到解决方案中才能发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM