EnvironmentView
in namespace DotVVM.Framework.Controls
Renders different content when the application is running in a specified environment and when it's not.
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.AppMode
key. If you host your application onSystem.Web
the value is automatically set toDevelopment
when 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>
Properties
Name | Type | Description | Notes | Default Value | |
---|---|---|---|---|---|
ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
Environments | String[] | Gets or sets a comma-separated list of hosting environments (e.g. Development, Production). |
attribute
static value
|
null | |
ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
bindable
|
True | |
InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
IsEnvironmentTemplate | ITemplate | Gets or sets the content rendered when the application is running in one of the specified environments. |
inner element
static value
default
|
null | |
IsNotEnvironmentTemplate | ITemplate | Gets or sets the content rendered when the application is not running in any of the specified environments. |
inner element
static value
|
null | |
RenderWrapperTag | Boolean | Gets or sets whether the control should render a wrapper element. |
attribute
static value
|
False | |
Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
bindable
|
True | |
WrapperTagName | String | Gets or sets the name of the tag that wraps the Repeater. |
attribute
static value
|
div |
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>