dotnet / dotnet/core

Using virtual directory with ASP.NET Core 3.1

Open
#4,893 4 comments 0 reactions 1 assignee Claimed by @Pilchie View on GitHub
area-aspnet
Dominant language
PowerShell
Stars
22k
Forks
4.9k
Avg merge
5d 5h
Merged PRs (30d)
29

Description

In ASP.NET framework 4.8 and below version the web application use IIS for processing and show data. Ans I web 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 in Asp.net application work 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

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

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.