Asp.net mvc Azure+;ASP.Net+;System.UnauthorizedAccessException:访问路径'/Content/img/CourseImages';被拒绝

Asp.net mvc Azure+;ASP.Net+;System.UnauthorizedAccessException:访问路径'/Content/img/CourseImages';被拒绝,asp.net-mvc,azure,file-upload,azure-web-app-service,Asp.net Mvc,Azure,File Upload,Azure Web App Service,我正在尝试在azure上使用asp.net上载文件(它不是VM)。 但我经常收到以下错误: System.UnauthorizedAccessException: Access to the path '/Content/img/CourseImages' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.InternalCreateDi

我正在尝试在azure上使用asp.net上载文件(它不是VM)。 但我经常收到以下错误:

System.UnauthorizedAccessException: Access to the path '/Content/img/CourseImages' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
以下是我的代码片段:

string courseImageFolderPath = ConfigurationManager.AppSettings["CourseImage"];
string courseImageFilePath = Path.Combine(courseImageFolderPath, fileName);
if (!Directory.Exists(courseImageFolderPath))
        Directory.CreateDirectory(courseImageFolderPath);
courseImage.SaveAs(System.Web.Hosting.HostingEnvironment.MapPath(courseImageFilePath));

每个Azure Web应用程序都有一个临时的本地目录(
D:\local
)。当运行不再在VM上运行时,将删除此文件夹中的内容。此目录用于存储应用程序的临时数据。不建议web应用程序使用此文件夹

根据,我建议您在web应用程序文件夹的根目录下创建一个临时文件夹(
D:\home\site\wwwroot
),并使用它存储临时数据。或者正如jayendran所说,你可以用它上传你的图片

string tempFolder = Server.MapPath("~/TEMP");
if (!Directory.Exists(tempFolder))
{
    Directory.CreateDirectory(tempFolder);
}
有关更多详细信息,请参阅此


此外,应用程序服务似乎无法访问网络资源。因此,您要做的是模拟一个可以访问网络资源的用户来创建目录。请参阅此项。

为什么要将图像保存在webapps中?我认为您没有将图像保存到应用程序服务位置的权限。如果您想上传图像,可以使用blob容器(或其他存储帐户)。Azure Web App是一种PaaS模型,您只需托管代码,而不需要在其中上载图像。是的,创建了容器和blob,并且能够上载和下载文件。然而,log4net如何能够创建文件并能够在服务器上写入?因为我正在上传一个文件,而log4net正在同一位置创建一个文本文件。也许你可以参考这个。