0

Everything is working fine locally. But when deployed to Azure, loading the css shows this error:

Resource interpreted as Stylesheet but transferred with MIME type text/plain

It happens in all the browsers.

The application loads a spa in react.

These are the middlewares I am using in this order.

if (Environment.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();            
        app.UseStatusCodePagesWithReExecute("/Home/Error", "?statusCode={0}");
        app.UseStaticFiles();
        app.UseSpaStaticFiles();
        app.UseOurCustomAuthenticate();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action}/{id?}");
            routes.MapRoute(
                name: "api",
                template: "api/{controller}/{action}/{id?}");
        });

        app.UseSpa(spa =>
        {
            spa.Options.SourcePath = "ClientApp";

            if (Environment.IsDevelopment())
            {
                spa.UseReactDevelopmentServer(npmScript: "start");
            }
        });

The custom authenticate middleware that we are using checks if the path starts with "/styles" it will not do anything and let it load.

This is the cshtml file where I include the css file:

<!DOCTYPE HTML>
<html>
<head>        
    <link rel="stylesheet" type="text/css" href="~/styles/notFound.css">
</head>
<body class="body-content">

This is where the styles and images are

enter image description here

The image is being loaded properly on the server, only the style have this problem.

So in my custom middleware I did this:

if (httpContext.Request.Path.StartsWithSegments("/styles"))
{
     httpContext.Response.ContentType = "text/css";
}

Now the content-type is correct in the network tab, but the style is not still loading. When I click on the css file it is an empty file.

I have read a lot of posts regarding this issue, but couldn't still solve it.

Andi Keikha
  • 1,246
  • 2
  • 16
  • 37
  • I'm curious what would happen if you call your custom authentication middleware before `app.UseStaticFiles()`. – Chris Pratt Jul 16 '19 at 14:30
  • Is the stylesheet actually deployed? Does it exist in Azure? – Morpheus Jul 16 '19 at 14:56
  • @ChrisPratt I commented out the custom middleware, and deployed. Still no change. I don't think that middleware is the problem. – Andi Keikha Jul 16 '19 at 16:25
  • @Morpheus I pulled the container to my local, looked at the content. The folder was Style with capital "S" not small "s". I have renamed that while ago and it was correct in my local, but looking at the code on the source control server, I saw that git didn't reflect that change, because apparently git is case-insensitive. So I update that on the source control server directly and it fixed the issue. Thank you! – Andi Keikha Jul 16 '19 at 17:14
  • Great that you found the problem :) – Morpheus Jul 17 '19 at 08:11

1 Answers1

0

At this point I had to see if the stylesheet is actually deployed.

To do so, I pulled the contianer and run it locally to see what files are copied there.

I found that the styleSheet is copied under a folder "Styles" with capital "S" instead of "styles" with small "s". We use git for our source control and git didn't catch the rename I made to this folder.

This is how to commit such a change with git case sensitive. Renaming the folder properly fixed the problem for me.

Andi Keikha
  • 1,246
  • 2
  • 16
  • 37