Environment Tag Helper

By Peter Kellner

The Environment Tag Helper conditionally renders its enclosed content based on the current hosting environment. Its single attribute names is a comma separated list of environment names, that if any match to the current environment, will trigger the enclosed content to be rendered.

Environment Tag Helper Attributes


Accepts a single hosting environment name or a comma-separated list of hosting environment names that trigger the rendering of the enclosed content.

These value(s) are compared to the current value returned from the ASP.NET Core static property HostingEnvironment.EnvironmentName. This value is one of the following: Staging; Development or Production. The comparison ignores case.

An example of a valid environment tag helper is:

<environment names="Staging,Production">
  <strong>HostingEnvironment.EnvironmentName is Staging or Production</strong>

Additional resources