0

In ASP.NET framework 4.8 and below version the web application use IIS for processing and show data. And when we need to work with other resource like folders and network resource we can easily create Virtual Directory in IIS and map to physical path and my application work theme like normal folder. but in Net Core we use Kestrel and IIS work as a proxy and Virtual Directory not recognized by Kestrel. I use this code but not work in function. Write this section in Configure Function

app.UseFileServer(new FileServerOptions
{
 FileProvider = new PhysicalFileProvider(@"E:\\MyFiles"),
 RequestPath = new PathString("/PFiles"),
 EnableDirectoryBrowsing = true
});

and this is my code :

var folder = Path.Combine(environment.WebRootPath, "temp");


                var fileName = Path.Combine(environment.WebRootPath, "temp\\test.jpeg");

                var basePath = Path.Combine(environment.WebRootPath, "PFiles");
               
                
                var yearPath = Path.Combine(basePath, "2020");
                var monthpath = Path.Combine(basePath, "2020", "06");

                if (!Directory.Exists(yearPath))
                {
                    Directory.CreateDirectory(yearPath);
                }
                if (!Directory.Exists(monthpath))
                {
                    Directory.CreateDirectory(monthpath);
                }

                var dpath = Path.Combine(basePath, "2020", "06");

                var destinationPath = Path.Combine(environment.WebRootPath, dpath);


                System.IO.File.Move(fileName, destinationPath);

but I receive Access denied Error or create directory inside of wwwroot folder. So, what must I do?

1
  • Show the actual error page. Commented Jun 30, 2020 at 17:50

1 Answer 1

2

you get this error because iis default account does not have enough permission to access the folder.

you could try to assign the iis_iusrs , iusr, or IIS AppPool<myappoolname> permission to the folder where you want to create directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.