在ASP.NET Core 2的layout.cshtml中使用和路由较少的文件 [英] Using and routing Less file in the layout.cshtml in ASP.NET Core 2

查看:291
本文介绍了在ASP.NET Core 2的layout.cshtml中使用和路由较少的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了





解决方案

文档 StaticFiles中间件:
$ b


如果用户请求一个未知文件类型的文件,静态文件中间件会返回一个HTTP 404(Not Found)响应。


这似乎是这里发生的事情。如果你想服务少,那么你需要为其添加映射

  var provider = new FileExtensionContentTypeProvider(); 
provider.Mappings [。less] =plain / text;

app.UseStaticFiles(新的StaticFileOptions
{
ContentTypeProvider =提供者
});


I've used a template for admin section (bootstrap admin template) in my project and installed it from Bower and I've applied ASP.NET Core 2.

When I run the project, I get an error that is:

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

in theme.less

But the file, theme.less, exists in the path!! I don't know why browsers cannot recognize the file.

For routing the theme.less file I did:

<link rel="stylesheet/less" type="text/css" href="~/lib/bootstrap-admin-template/public/assets/less/theme.less">

How can I fix this problem?

解决方案

In the documentation on the StaticFiles middleware:

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

That seems to be what's happening here. If you want to serve less then you need to add a mapping for it:

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".less"] = "plain/text";

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

这篇关于在ASP.NET Core 2的layout.cshtml中使用和路由较少的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆