Reputation: 1072
In my .NET Core web app, I want to upload PDF files and display them later. I want to store these files in a folder outside of the project folder on a Windows 2016 server (eg. C:\files).
At first I thought, I could use a virtual directory pointing to C:\files on the IIS server but it seems like that's not possible in .NET Core anymore.
As per this blog post (https://www.jauernig-it.de/asp-net-coreiis-serving-content-from-a-file-share/ ), one should use UseFileServer() instead. Is it possible to configure UseFileServer with a folder outside of the project?
This is what I've tried:
In my Startup.cs
app.UseFileServer(new FileServerOptions
{
FileProvider = new
PhysicalFileProvider(@"\\servername\C:\folder"),
RequestPath = new PathString("/Uploads"),
EnableDirectoryBrowsing = false
});
For testing, I stored an image inside of the folder and then tried:
<img src="/Uploads/image.jpg" />
Unfortunately, the image is not being displayed. Am I missing something?
Upvotes: 0
Views: 1877
Reputation: 1279
The problem in your code is, that \\servername\C:\folder
would expect a directory named folder
on the share drive C:
which is located on a remote server with the name servername
.
But in your case the folder is on the same machine as IIS. So I would only be C:\folder
.
Upvotes: 1