Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular .NET Core 3.1提供静态文件_Angular_Asp.net Core 3.1_Asp.net Core Staticfile - Fatal编程技术网

Angular .NET Core 3.1提供静态文件

Angular .NET Core 3.1提供静态文件,angular,asp.net-core-3.1,asp.net-core-staticfile,Angular,Asp.net Core 3.1,Asp.net Core Staticfile,我在.Net Core 3.1和Angular 10中有一个应用程序 在我的Startup.cs中,我有以下代码: app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,"Pictures")), RequestPath = new PathS

我在.Net Core 3.1和Angular 10中有一个应用程序

在我的Startup.cs中,我有以下代码:

app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
 {
  FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath,"Pictures")),
  RequestPath = new PathString("/Pictures") 
 });
文件保存到正确的路径中,但当我想从web显示它们时,路径为:

http://mywebsite/Pictures/pic.jpg,我刚拿到一张:

没有错误,没有404或401

有人能帮忙吗


谢谢。

静态文件存储在项目的web根目录中。默认目录为{content root}/wwwroot 我解决了这个问题:

在我的控制器中,我写了一个绝对路径: C:

我改为environment.ContentRootPath,它可以正常工作


谢谢您的回答。

文件被保存到正确的路径中
这是什么意思?文件是否存储在
wwwroot/Pictures
中?您不需要使用第二个
UseStaticFiles
没有错误,没有404或401。
您检查过浏览器的开发工具吗?图像与页面本身分开加载,因此图像的404不会导致整个页面失败。@PanagiotisKanavos我删除了UseStaticFiles(),得到了相同的结果。开发人员的工具中也没有错误。谢谢@Chameera,这是我最后做的,但Microsoft告诉我可以更改默认值: