最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Access denied on write a file in wwwroot folder by ASP.NET Core - Stack Overflow

programmeradmin3浏览0评论

I try to upload a file to a website (wwwroot folder) using this code:

string folderPath = Path.Combine(_env.WebRootPath, "Attach", persianDate);

bool folderExists = Directory.Exists(folderPath);

if (folderExists == false)
{
    Directory.CreateDirectory(folderPath);
}

using (var stream = new FileStream(folderPath, FileMode.Create))
{
    await model.File.CopyToAsync(stream);
}

I can create the folder without any problems, but when I try to copy the file into it, I get error that says "access denied".

I modify permission of folder like this:

but this still doesn't work for me.

I know that DefaultAccount has X icon on it.

What is the problem?

I try to upload a file to a website (wwwroot folder) using this code:

string folderPath = Path.Combine(_env.WebRootPath, "Attach", persianDate);

bool folderExists = Directory.Exists(folderPath);

if (folderExists == false)
{
    Directory.CreateDirectory(folderPath);
}

using (var stream = new FileStream(folderPath, FileMode.Create))
{
    await model.File.CopyToAsync(stream);
}

I can create the folder without any problems, but when I try to copy the file into it, I get error that says "access denied".

I modify permission of folder like this:

but this still doesn't work for me.

I know that DefaultAccount has X icon on it.

What is the problem?

Share Improve this question edited Mar 14 at 5:07 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 14 at 4:02 hmahdavihmahdavi 2,3824 gold badges47 silver badges98 bronze badges 3
  • Hi hmahdavi, please navigate to BuySaleStrap folder and click the properties, find the Security tab then add IIS_IUSRS and IUSR , then check again. – Jason Commented Mar 14 at 6:36
  • This does not work – hmahdavi Commented Mar 14 at 12:27
  • Please try to run the application via the dotnet cli command like dotnet project_name.dll directly, and check if it works or not. – Jason Commented Mar 14 at 12:39
Add a comment  | 

1 Answer 1

Reset to default 1

I used app.UseFileServer(); in program.cs and solved

发布评论

评论列表(0)

  1. 暂无评论