gpt4 book ai didi

c# - 在 ASP.NET 5 中找不到 CSS 文件

转载 作者:太空狗 更新时间:2023-10-29 18:19:58 25 4
gpt4 key购买 nike

我在 wwwroot 中创建了一个 Content 文件夹,因为我读到应该在文档中添加样式表和脚本等客户端内容,但是当我添加到我拥有的 View 并构建项目时,它找不到文件。这样做的正确方法是什么?

<link href="~/content/style.css" rel="stylesheet" />

我很确定 wwwroot 已正确添加到 project.json。

"webroot": "wwwroot"

最佳答案

您需要在 Startup 中启用 ASP.NET Core 静态文件处理:

public void Configure(IApplicationBuilder application)
{
// Add static files to the request pipeline.
application.UseStaticFiles();

// Add MVC to the request pipeline.
application.UseMvc();
}

Visual Studio 2017 (csproj)

除非您使用 Microsoft.AspNetCore.All 包,否则您还需要将此添加到您的 csproj:

<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />

Visual Studio 2015 (xproj + project.json)

您还需要将其添加到您的 project.json 中:

"dependencies": {
"Microsoft.AspNetCore.StaticFiles": "1.0.0"
// ...Omitted
}

关于c# - 在 ASP.NET 5 中找不到 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33078695/

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