Refused to apply style from <URL> because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

Avbl Sundari 1 Reputation point
2021-05-13T06:24:58.623+00:00

HI Team,

I'm trying to to bundling CSS files after minification. My application is ASP.net Core 4.5 not MVC. I have created bungleconfig class file and written below code

public class bundleconfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{

        bundles.Add(new StyleBundle("~/bundles/css").Include(
                      "~/Content/bootstrap.min.css",
                      "~/Content/main.min.css",
                       "~/Content/theme.min.css",
                      "~/Content/bootstrap-select.min.css",
                      "~/Content/bootstrap-slider.min.css",
                      "~/Content/bootstrap-theme.min.css",
                      "~/Content/bootstrap-treeview.min.css", 
                      "~/Content/bootstrap-datetimepicker.min.css",
                       "~/Content/buttons.dataTables.min.css",
                        "~/Content/dataTables.bootstrap.min.css",
                         "~/Content/jquery-ui.min.css",
                        "~/Content/bootstrap-treeview.min.css"
                  )
            );
        BundleTable.EnableOptimizations = true;
    }
}

in Main.Maste I added below code in head tag

<%: System.Web.Optimization.Styles.Render("~/bundles/css") %>

After running code MY css is not bundled and nothing applied as well. Getting error

Refused to apply style from <URL> because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Please help

Thanks In advance

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,483 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,922 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,081 Reputation points
    2021-05-14T07:59:41.957+00:00

    Hi @Avbl Sundari ,
    I think the MIME Type error could be due to the css path not being correct. How do add css file in your page? You could check it. And you could try use absolute path.
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Frédéric Druilhet 1 Reputation point
    2021-07-21T08:56:22.603+00:00

    Same problem here. Resolved in setting BundleTable.EnableOptimizations to false

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.