html - 在 ASP.NET Core 2 中的 layout.cshtml 中使用和路由 Less 文件

标签 html asp.net razor asp.net-core less

我用过 a template for admin section (bootstrap admin template)在我的项目中并从 Bower 安装它我已经申请了 ASP.NET Core 2 .

当我运行项目时,我收到一个错误:

FileError: 'http://localhost:52125/lib/bootstrap-admin-template/public/assets/less/theme.less' wasn't found (404)

in theme.less



但是文件,theme.less , 存在于路径中!!我不知道为什么浏览器无法识别该文件。

用于路由 theme.less我做的文件:
<link rel="stylesheet/less" type="text/css" href="~/lib/bootstrap-admin-template/public/assets/less/theme.less">

我该如何解决这个问题?

The error

Path of theme.less file

Tree Structure Of Files and Folders

最佳答案

documentation在 StaticFiles 中间件上:

If the user requests a file of an unknown file type, the static file middleware returns a HTTP 404 (Not Found) response.



这似乎就是这里发生的事情。如果您想减少服务,则需要add a mapping为了它:
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".less"] = "plain/text";

app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = provider
});

关于html - 在 ASP.NET Core 2 中的 layout.cshtml 中使用和路由 Less 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49603561/

相关文章:

asp.net-mvc - 自定义助手无法正常工作

c# - 分组输出集合中的项目

html - CSS IE问题

html - 如何在打印时为 html 页面提供页面边框?

javascript - 在表单按钮 css 中的文本旁边添加图像

c# - Double.ToString 用于格式化

c# - 缺少根元素

asp.net - 在 web.config 中硬编码密码是否安全?

html - 用于使全身背景可点击的纯 HTML/CSS 解决方案

jquery - 对自定义属性执行客户端验证