【发布时间】:2021-03-01 13:50:41
【问题描述】:
剃须刀页面上有一个代码,像这样,
<img src="Images/Tree.jpg" asp-append-version="true" width="286" height="135" />
运行后页面无法显示图片,是不是有什么问题?
【问题讨论】:
标签: asp.net-core razor-pages asp.net-core-2.1
剃须刀页面上有一个代码,像这样,
<img src="Images/Tree.jpg" asp-append-version="true" width="286" height="135" />
运行后页面无法显示图片,是不是有什么问题?
【问题讨论】:
标签: asp.net-core razor-pages asp.net-core-2.1
您的Images 文件夹应放在wwwroot 下。
试试这段代码:
<img src="~/Images/Tree.jpg" asp-append-version="true" width="286" height="135"/>
更多详情可以看这个link。
如果您的 Images 静态文件位于 wwwroot 文件夹之外,要提供这些文件并使其按预期工作,您可以尝试:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseStaticFiles();
app.UseFileServer(new FileServerOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(env.ContentRootPath, "Images")),
RequestPath = "/Images"
});
//...
然后就可以输入网址访问了。
【讨论】: