首页 > 解决方案 > 如何在 ASP .NET Core 的 Area 中使用 css 文件或 js

问题描述

你知道 ASP .NET Core MVC 有一个wwwroot静态文件夹。我需要将我的自定义 js、css等放入Areas文件夹下的Content文件夹中。以前有人试过这个或有人知道怎么做吗?

标签: asp.net-coreasp.net-core-mvcareastatic-files

解决方案


如果我们区域的结构如下:

在此处输入图像描述

您需要将这些代码复制到启动下的配置部分 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" />

推荐阅读