gpt4 book ai didi

asp.net-core - ASP.NET Core 在通过浏览器访问时看不到图像

转载 作者:行者123 更新时间:2023-12-02 02:57:21 25 4
gpt4 key购买 nike

我创建了一个 ASP.NET Core 3.1 Web API 项目,在 IIS Express 上它与 Controller 完美配合。我创建了一个名为 images 的文件夹,并在其中复制了一些 .jpg 文件。

我的想法是使用 url 从我的 Xamarin 应用程序获取这些图像,例如

http://192.168.0.185:52493/img/lucas.PNG

但没有返回任何内容。然后我尝试将 url 直接写入 Internet Explorer,但没有任何反应,图像也没有显示在浏览器中。

知道它是什么吗?

最佳答案

如果您想从位于项目根目录的您自己的文件夹 img 访问您的文件,而不是默认的 wwwroot 文件夹,您需要配置 Static startup.cs 中的文件中间件 Configure 方法如下:

app.UseStaticFiles();// For the wwwroot folder

app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "img")),
RequestPath = "/img"
});
app.UseRouting();
//other middlewares

引用https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.2#serve-files-outside-of-web-root

关于asp.net-core - ASP.NET Core 在通过浏览器访问时看不到图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60823487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com