简体   繁体   English

Asp.Net Core 6 添加 Bootstrap 到脚手架 Identity _Layout.cshtml

[英]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.

相关问题 将Bootstrap连接到ASP.NET _Layout.cshtml文件 - Connecting Bootstrap to ASP.NET _Layout.cshtml file 在ASP.NET Core中的_Layout.cshtml中访问cookie - access cookie in _Layout.cshtml in ASP.NET Core ASP.NET Core 中的翻译问题,通过 ASP.NET _Layout.cshtml 中的核心本地化 - Problem with translation in ASP.NET Core via ASP.NET Core localization in _Layout.cshtml 如何将数据库中的数据添加到 ASP.NET Core MVC (.NET 6) 应用程序中的共享 _Layout.cshtml? - How do you add data from the database to the shared _Layout.cshtml in ASP.NET Core MVC (.NET 6) application? ASP.NET MVC中_layout.cshtml中的布局 - Layout in _layout.cshtml in ASP.NET MVC ASP.NET MVC引导程序-_Layout.cshtml有什么问题? - ASP.NET MVC Bootstrap - What is wrong with my _Layout.cshtml? 徽标未显示在 header _Layout.cshtml asp.net 核心 - Logo not showing in header _Layout.cshtml asp net core window.onload = function() in `_Layout.cshtml` 无限循环(ASP.NET Core) - window.onload = function() in `_Layout.cshtml` Infinity loop(ASP.NET Core) 将常见数据传递到ASP.Net MVC中的_Layout.cshtml中 - Passing common data into the _Layout.cshtml in ASP.Net MVC 在 Layout.cshtml Asp.net 中调用模型时出错 - Error when call model in Layout.cshtml Asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM