EnvironmentView
in namespace DotVVM.Framework.Controls
Usage & Scenarios
Allows to render content when an application is running on a specific environment (eg. Development, Production). We use an IEnvironmentNameProvider
service to get the name of the current environment. The default implementation behaves differently on OWIN and on ASP.NET Core.
- On ASP.NET Core: We simply use the IHostingEnvironment.EnvironmentName property to get the name.
- On OWIN: We use a value stored in the environment dictionary under the
host.AppModekey. If you host your application onSystem.Webthe value is automatically set toDevelopmentwhen debugging is enabled in Web.config.
In both cases the default environment name is Production. You may override this behavior by implementing your own IEnvironmentNameProvider.
Sample 1: EnvironmentView
The Environments property contains a comma-separated list of environment names.
The IsEnvironmentTemplate defines the content rendered when the application is running on one of the specified Environments.
The IsNotEnvironmentTemplate defines the content rendered on other environments.
<dot:EnvironmentView Environments="Production,Development">
Production or Development environment.
</dot:EnvironmentView>
<dot:EnvironmentView Environments="Staging">
<IsEnvironmentTemplate>
Staging environment.
</IsEnvironmentTemplate>
<IsNotEnvironmentTemplate>
Other environment.
</IsNotEnvironmentTemplate>
</dot:EnvironmentView>
HTML produced by the control
The control renders the contents of the IsEnvironmentTemplate or IsNotEnvironmentTemplate property. Optionally you can enable wrapper tag rendering using
the RenderWrapperTag property. The tag name can be changed using the WrapperTagName property.
<div>
<!-- Contents of the IsEnvironmentTemplate or IsNotEnvironmentTemplate -->
</div>