Why does the environment tag helper work on my machine but not on Azure?

This is a section on our _Layout.cshtml that I'm about to throw out the window.

<!-- CSS Scripts -->
    <environment include="Development">
        <script src="/ts/CS.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
        <script src="/ts/CS.Url.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
        <script src="/ts/CS.Settings.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
        <script src="/ts/CS.Alert.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
        <script src="/ts/CS.Modal.js" asp-append-version="true" abp-ignore-src-modification="true"></script>
    </environment>
    <environment include="Staging,Production">
        <script abp-src="/ts/CS.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Url.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Settings.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Alert.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Modal.js" asp-append-version="true"></script>
    </environment>

We use the environment tag helper in some spots to either use .min.js or .js, useful for debugging. I can see that if I personally set the ASPNETCORE_ENVIRONMENT variable from "Development" to "Production" that the tag helper continues to render the right content.

However, when I then push this through to be hosted on Azure - the content is missing completely.

Things I've tried:

  • Tried changing the value in azure config - no change.
  • Originally we had names, changed to include - no change. Still works on dev machine.

What is going on here?! Is this not what other people do?

Staging, production is not understandable to the server. You need to change this as follow.

If You are working in local than our script will work which is inside

<environment include="Development">
</environment>

if You are working on server like azure and others than our script will work which is inside

<environment exclude="Development">
</environment>

You need to change your following code

<environment include="Staging,Production">
        <script abp-src="/ts/CS.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Url.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Settings.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Alert.js" asp-append-version="true"></script>
        <script abp-src="/ts/CS.Modal.js" asp-append-version="true"></script>    </environment>

as

<environment exclude="Development">
                <script abp-src="/ts/CS.js" asp-append-version="true"></script>
                <script abp-src="/ts/CS.Url.js" asp-append-version="true"></script>
                <script abp-src="/ts/CS.Settings.js" asp-append-version="true"></script>
                <script abp-src="/ts/CS.Alert.js" asp-append-version="true"></script>
                <script abp-src="/ts/CS.Modal.js" asp-append-version="true"></script> 
   </environment>

It will work at any server.

Environment Tag Helper in ASP.NET Core, ASP.NET Core Environment Tag Helper defined including all properties. Machine Learning & Data. ML.NET .NET for The Environment Tag Helper's single attribute, names , is a comma-separated list of environment names. If any of the EnvironmentName is not Development</strong> </environment>� Tags can be managed from the Azure portal, but this can be inefficient if you have lots of resources to work with. That’s where command line options such as Azure CLI come in handy. Here are some basic tagging operations to give you a feel for the syntax; refer to the official documentation to see everything you can do with tags in Azure CLI .

The exclude="Development" works if you want to apply the same settings to all other environment except Development. But I came across a time when I need to have different settings for staging and production. So I had to be specific.

The solution I use in order for the environment tag helper to work on Azure is that you need to create an entry for the ASPNETCORE_ENVIRONMENT under Settings -> Configuration -> Application settings on Azure:

If you don't have that defined on Azure, when you publish, it will default to Production if I remember correctly, which is weird.

Use multiple environments in ASP.NET Core, The Environment Tag Helper's single attribute, names , is a comma-separated list of environment names. If any of the provided environment� In many cases, HTML Helpers provide an alternative approach to a specific Tag Helper, but it's important to recognize that Tag Helpers don't replace HTML Helpers and there's not a Tag Helper for each HTML Helper. Tag Helpers compared to HTML Helpers explains the differences in more detail. What Tag Helpers provide

I was having the same issue with asp.net 3.0. It was rendering environment on local properly but when I deployed to Azure it stopped detecting it and rendering both the environment as it is.

Here is the solution. Just add the below line in your _Layout.cshtml file in the beginning.

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

it will fix the issue.

thanks

Working with Multiple Environments — ASP.NET documentation, The Environment Tag Helper uses the value of IHostEnvironment. case- sensitive. Linux environment variables and values are case-sensitive by default. The environment for local machine development can be set in the $Env: ASPNETCORE_ENVIRONMENT = "Staging" dotnet run --no-launch-profile. Azure is a fast, flexible, and affordable platform, and its pricing and capabilities make it the best public cloud offering on the market. Now let’s take a look at how to put it to work for you. 1. Enhance and Implement Backup and Disaster Recovery. Azure is a backup and disaster recovery dream tool. Why?

<environment> tags emitted to markup � Issue #534 � dotnet , Environment variables are used to indicate which environment the In addition, you can use the Environment tag helper to include certain sections in your view pages (which typically should not be run in production) and special database� How do you wanna sync the data if the machine is non persistent. That would mean that you would sync the entire OneDrive for business after logon, that sounds a bit odd. My guess is that you would need to have an Appvolumes writable volume for that, this way the synced data will be on the writable disk and there after logon.

Working with multiple environments, GitHub is home to over 50 million developers working together to host and review code guardrex changed the title <environment> tags omitted to markup very likely you haven't imported the taghelper at the top of the layout. taking advantage of the fact that my Azure VM's have the same prefix ("VM") . How they work. Fabric softeners typically come in 2 different forms – a liquid used in the washing machine or a coated sheet used in the dryer. They are designed to prevent static, help with wrinkles, add a scent, and make the materials feel softer. They do this by covering the fabric in a thin, lubricating film.

Working with Environments and Launch Settings in ASP.NET Core, Your project can have multiple debug profiles that set environment variables differently. Environment variables stored in launchSettings.json are not secured in any way The method for setting the environment depends on the operating system. To get started with using tag helpers in your application see Introduction to� Azure Sentinel Put cloud-native SIEM and intelligent security analytics to work to help protect your enterprise Azure Stack Build and run innovative hybrid applications across cloud boundaries Security Center Unify security management and enable advanced threat protection across hybrid cloud workloads

Comments
  • when you write "the value in azure config", do you mean you set the "ASPNETCORE_ENVIRONMENT" in your webservice configuration?
  • Specifically in the AppService > Configuration > Application Settings. I didn't add it there, it was there by default and is correctly set to "Production". Here's what it looks like: link
  • You're right. Looking at a template generated today, that's exactly what it looks like. I swear this used to be different ..