0

I'm developing a web site and started from the MVC project template. While experimenting with custom exception handling, I altered ASPNETCORE_ENVIRONMENT to "Production" in launchSettings.json (IIS Express) and found that the footer defined in _Layout.cshtml moved from the bottom of the screen to immediately below the rest of the content.

I suspected that I had done something wrong in my own code but after searching for something CSS related varying by environment and also moving / removing CSS files, the problem remained.

To get back to basics, I created a new project using the MVC template and ran it as development and then production and it exhibited the same behaviour.

The image shows the position of the footer with the production setting: enter image description here

My CSS skills are poor so it may be something simple but I can't find the cause.

Arnab
  • 4,216
  • 2
  • 28
  • 50
MikeP
  • 11
  • 3
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 01 '22 at 08:24
  • Hi Arnab. The problem can be reproduced by using Visual Studio (I use 2022), creating a new project from the MVC template and then running as development and then production as I explain by editing ASPNETCORE_ENVIRONMENT. The problem is somewhere within Microsoft's code not mine. – MikeP Dec 01 '22 at 08:52
  • Hi Mike, you need to create a [mcve] within the question otherwise it is off topic for SO. Please use the edit your question and use the snippet button to add some code – Pete Dec 01 '22 at 09:38
  • Sorry Pete. I would not know what to provide. The minimal reproducible example is to use VS 2022 and simply create a new MVC project and then run it, see where the footer is displayed and then edit ASPNETCORE_ENVIRONMENT in launchSettings.json to "Production" run it again and see that the footer position changes. I cant find where in the framework the CSS is being varied based on environment. – MikeP Dec 01 '22 at 09:50

1 Answers1

1

I am grateful to AgaveJoe on another forum for the solution he provided...

CSS isolation works in development or a published application. Add builder.WebHost.UseStaticWebAssets(); to the program.cs if you are running the application on your development machine using an environment other than Development.

var builder = WebApplication.CreateBuilder(args);
    
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.WebHost.UseStaticWebAssets();
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
MikeP
  • 11
  • 3