Bootstrap5 和其他自定义 CSS 未加载到 .net 核心 web api

Bootstrap5 and other custom CSS not loaded in .net core web api

您好,目前我正在一个 api 的项目中,该项目在本地呈现一个 cshtml 模板以用于报告目的。 问题是,当使用 bootstrap 的 cdn link 时,cshtml 会一致呈现,但当在本地使用静态 css 文件时,所有样式都不会应用。 我在网上看过,发现您需要在 startup.cs 中使用静态文件中间件,但它也不起作用。

这是我目录的屏幕截图:

这是我在配置方法中添加的代码:

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

这是在 cshtml 文件中加载 css 的代码示例:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>@Model.title</title>
    @*<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>*@
    <link href="grafana.light.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="bootstrap.min.css"/>
</head>

有人解决这个问题吗? 亲切的问候

更新:

Directory.GetCurrentDirectory() return the folowing path:

andh项目所在文件夹:

出于保密目的,我不得不隐藏文件夹的名称,但我可以证明它是同一个文件夹。

我将把这个关闭,因为我认为问题与静态文件无关,而是来自我得到的生成的 html。相反,我会 post 另一个问题,询问如何从 cshtml 渲染 html 文件并启用 css 和静态文件。