笔者的前端文件如下
笔者增加Bootstrap 4 和 FontAwersome(字体图标),因为Bootsrap 4已经不再包含图标了。
ASp.Net Core 中,通常在 _Layout.cshtml 文件设置全局css、js文件,
其中有两个标签
<environment include="Development"> </environment>
<environment exclude="Development"> </environment>
environment include="Development"
表示网站若在开发环境运行,则使用里面的文件。
environment exclude="Development"
表示网站不是开发环境时,使用里面的文件。
那么他们的作用是什么呢?
一般来说,开发环境,使用 本地的、未编译(压缩等处理)
的前端文件。
而部署网站后,使用 CDN 加速的前端文件。
举例如下
在 _Layout.cshtml 设置引入的 css、js 文件如下
CSS
<environment include="Development"> <link rel="stylesheet" href="https://www.atool.online/article/~/bootstrap4/css/bootstrap.css" rel="external nofollow" /> <link rel="stylesheet" href="https://www.atool.online/article/~/FontAwesome/css/font-awesome.css" rel="external nofollow" /> <link rel="stylesheet" href="https://www.atool.online/article/~/css/site.css" rel="external nofollow" /> </environment> <environment exclude="Development"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="external nofollow" asp-fallback-href="https://www.atool.online/article/~/bootstrap4/css/bootstrap.min.css" rel="external nofollow" asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous" /> <link rel="stylesheet" href="https://www.atool.online/article/~/FontAwesome/css/font-awesome.min.css" rel="external nofollow" /> <link rel="stylesheet" href="https://www.atool.online/article/~/css/site.min.css" rel="external nofollow" asp-append-version="true" /> </environment>
JS文件
<environment include="Development"> <script src="https://www.atool.online/article/~/lib/jquery/dist/jquery.js"></script> <script src="https://www.atool.online/article/~/bootstrap4/js/bootstrap.js"></script> <script src="https://www.atool.online/article/~/bootstrap4/js/bootstrap.bundle.js"></script> <script src="https://www.atool.online/article/~/js/site.js" asp-append-version="true"></script> </environment> <environment exclude="Development"> <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js" asp-fallback-src="https://www.atool.online/article/~/lib/jquery/dist/jquery.min.js" asp-fallback-test="window.jQuery" crossorigin="anonymous" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT"> </script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" asp-fallback-src="https://www.atool.online/article/~/bootstrap4/js/bootstrap.min.js" asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal" crossorigin="anonymous" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"> </script> <script src="https://www.atool.online/article/~/bootstrap4/js/bootstrap.bundle.min.js"></script> <script src="https://www.atool.online/article/~/js/site.min.js" asp-append-version="true"></script> </environment>
模板、前端文件下载地址
https://dev.tencent.com/u/whuanle/p/asp.netcoreaaaaaaaaaa/git 查看git内容
https://git.dev.tencent.com/whuanle/asp.netcoreaaaaaaaaaa.git 直接下载
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持阿兔在线工具。