.NET Core 3.1 Serve static Files

475 views Asked by At

I have an app in .Net Core 3.1 and Angular 10.

In my Startup.cs, I have the folowing code:

app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
 {
  FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,"Pictures")),
  RequestPath = new PathString("/Pictures") 
 });

The files are saved into the correct path but when I want to display them from web with the path:

http://mywebsite/Pictures/pic.jpg, I just get a:

enter image description here

without errors, no 404 or 401.

Can someone help?

Thanks.

1

There are 1 answers

0
Laurent Knafo On

I solved the problem:

In my controller I wrote an absolute path: C:...

I changed to environment.ContentRootPath and it works.

Thanks for the answers.