Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ian 3 posts 73 karma points notactivated
    Jun 22, 2023 @ 07:50
    Ian
    0

    How to conditionally add to the Master head based on environment eg Dev Test etc.

    I've got a requirement to add script to the head of the Master.cshtml file, but not if the environment is development, so I'm wondering how to do this.

    I suspect there must be something built in to do this, I've looked I just can't find it.

    In startup.cs, I see IWebHostEnvironment offers an EnvironmentName property, but that's in the apps bootstraping code.

  • Daniel 14 posts 104 karma points
    Jun 22, 2023 @ 08:04
    Daniel
    0

    Hi.

    Some different ways to approached this.

    I think I would solve this by using the appsetting. Read more about it here .

    You can get a property from the cshtml using the injector like this:

    @inject Microsoft.Extensions.Configuration.IConfiguration Configuration
    var Env = Configuration["Enviroment:Production"];
    
Please Sign in or register to post replies

Write your reply to:

Draft