在主机上上传图片访问被拒绝
Access denied for upload image on host
我使用以下代码将图片复制到路径
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.
需要检查和验证的内容很少。
- 确保在托管环境中,您已经在 wwwroot 下创建了上传目录。
- 如果不存在则创建它。
- 您必须授予 apppool 权限(您的应用程序 运行 所在的应用程序池)访问上传目录的权限。
以上内容是必需的,并且您的代码在应用程序池上下文中执行。
我使用以下代码将图片复制到路径
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.
需要检查和验证的内容很少。
- 确保在托管环境中,您已经在 wwwroot 下创建了上传目录。
- 如果不存在则创建它。
- 您必须授予 apppool 权限(您的应用程序 运行 所在的应用程序池)访问上传目录的权限。
以上内容是必需的,并且您的代码在应用程序池上下文中执行。