ASP.NET Core路由到wwwroot中的文件

时间:2019-01-08 14:24:18

标签: c# html css asp.net-core

我有一个ASP.NET Core Web应用程序,在已发布的网站的文件夹images下有一个文件夹wwwroot

当尝试在_Layout.cshtml中访问该images文件夹时,我很难为该文件夹设置正确的路径。

我添加了StaticFiles中间件,但是在我尝试添加带有背景样式的标头的特定情况下它不起作用:

<header class="main-header" role="banner" style="background: url(../MyImages/bg-header.png) transparent repeat-x 0 0">

静态文件配置:

        app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(
                Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images")),
            RequestPath = "/MyImages"
        });

我在这里想念什么? 没关系,我是Web开发的新手。

谢谢。

编辑: 这个:

<a href="~/" title="Home" rel="home">
        <img src="~/MyImages/logo.png" style="background-color:white;" alt="Home">

无论在什么页面上都可以正常工作。

0 个答案:

没有答案