在主机上上传图像的访问被拒绝

时间:2021-04-11 11:38:06

标签: c# asp.net-core plesk

我使用以下代码将图片复制到路径

public async Task<object> UploadImage(IFormFile file)
{
string path = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\uploads\");
string fileName = file.FileName;

string fullPath = Path.Combine(path, fileName);

await file.CopyToAsync(new FileStream(fullPath, FileMode.Create));
}

这段代码在本地主机上运行良好,但是当我在主机上发布我的应用程序时出现以下错误:

Access to the path C:\Inetpub\vhosts\site.com\wwwroot\uploads\file.png' is denied.

1 个答案:

答案 0 :(得分:0)

需要检查和验证的东西很少。

  1. 确保在托管环境中,您已在 wwwroot 下创建了上传目录。
  • 如果不存在则创建它。
  1. 您必须将上传目录的访问权限授予 apppool 权限(您的应用程序在其下运行的应用程序池)。

以上内容是必需的,并且您的代码在 apppool 上下文中执行。

相关问题