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 |1 Answer
Reset to default 1I used app.UseFileServer();
in program.cs and solved
Security
tab then addIIS_IUSRS
andIUSR
, then check again. – Jason Commented Mar 14 at 6:36dotnet project_name.dll
directly, and check if it works or not. – Jason Commented Mar 14 at 12:39