[英]Asp.Net Core 6 Add Bootstrap to scaffolded Identity _Layout.cshtml
I am using VS2022 Preview and have created a Single Page Application using Angular and the default project in VS2022.我正在使用 VS2022 预览版,并使用 Angular 和 VS2022 中的默认项目创建了一个单页应用程序。 I have scaffolded the Identity pages so that I can change the styles by overriding bootstrap with one from Bootswatch.
我搭建了身份页面的脚手架,以便我可以通过使用 Bootswatch 中的一个覆盖引导程序来更改 styles。 However, when I try to reference bootstrap from my lib folder in wwwroot like this:
但是,当我尝试从 wwwroot 中的 lib 文件夹中引用 bootstrap 时,如下所示:
<link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.min.css" />
Then I get the error:然后我得到错误:
Refused to apply style from 'https://localhost:5002/lib/bootstrap/css/bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
I've tried various file paths here but nothing seems to work.我在这里尝试了各种文件路径,但似乎没有任何效果。 Any help would be great as this seems like a trivial task!
任何帮助都会很棒,因为这似乎是一项微不足道的任务!
The _Layout.cshtml
page is generated by Scaffolded Identity, right? _Layout.cshtml
页面是Scaffolded Identity生成的吧?
If that is case, the Identity package also contains the Bootstrap reference, and by default the _Layout.cshtml
page already adds the bootstrap reference using the following code, you could consider using it as a workaround.如果是这种情况,Identity package 还包含 Bootstrap 引用,默认情况下
_Layout.cshtml
页面已经使用以下代码添加了 bootstrap 引用,您可以考虑使用它作为解决方法。
<link rel="stylesheet" href="~/Identity/lib/bootstrap/dist/css/bootstrap.min.css" />
The result as below:结果如下:
Besides, you could also try to use CDN reference:此外,您还可以尝试使用 CDN 参考:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
Please move your lib folder to wwwroot folder and reference it from there.请将您的 lib 文件夹移动到 wwwroot 文件夹并从那里引用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.