asp.net-core - 如何在 ASP .NET Core 的 Area 中使用 css 文件或 js
问题描述
你知道 ASP .NET Core MVC 有一个wwwroot静态文件夹。我需要将我的自定义 js、css等放入Areas文件夹下的Content文件夹中。以前有人试过这个或有人知道怎么做吗?
解决方案
如果我们区域的结构如下:
您需要将这些代码复制到启动下的配置部分
app.UseStaticFiles()
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new
PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),
"Areas\\Foo\\Content")),
RequestPath = new PathString("/Foo/Content")
});
并链接如下文件:
<link rel="stylesheet" href="/Foo/Content/bootstrap.min.css" />
推荐阅读
- python - 使用 Selenium、BeautifulSoup 抓取网页耗时过长
- kubernetes - Helm 调试未知字段
- openlayers-5 - 在 OL5 中将 WFS 集成为 gml
- ruby-on-rails-3 - 我们如何在 rails 4 应用程序上添加 same_site 属性?
- vue.js - 我尝试使用 vuetify 在数据表中创建一个复选框单元格,但它不起作用
- python - pandas 中的连续中奖 ID
- asp.net-core - asp.net core中的“ResponseCache属性”和“ResponseCache中间件”有什么区别?
- vba - 数组 VBA 未填充分配的第一个值
- asp.net-core - EF Core 外键配置
- flutter - Flutter - 如何自动滚动 ListView 以使部分可见的平面按钮完全可见