DwsMetaTag
DwsMetaTag renders its DwsMetaTagEntry children into the document head. The tags belong to the page: they are removed again when you navigate away. Open the browser dev tools and inspect <head> to see them.
Several DwsMetaTag instances combine - for example one in a layout and one in a page. This page keeps most examples in one page-level DwsMetaTag, because the demo sections below load lazily; the "Multiple instances" example adds a second one.
API ReferenceBasic
Set exactly one key attribute per entry - MetaName, MetaProperty, MetaHttpEquiv, MetaCharset or MetaViewport - plus MetaContent where the key needs one.
Adds keywords, og:title and og:type to the head.
Show Code
MetaTag.razor
<DwsMetaTag Name='MetaTagDemo_Basic'>
<DwsMetaTagEntry Name='MetaTagDemo_Basic_Keywords' MetaName='keywords' MetaContent='DWS, Blazor, Meta Tag, Sample' />
<DwsMetaTagEntry Name='MetaTagDemo_Basic_OgTitle' MetaProperty='og:title' MetaContent='Sample Page Title' />
<DwsMetaTagEntry Name='MetaTagDemo_Basic_OgType' MetaProperty='og:type' MetaContent='website' />
</DwsMetaTag>Scheme and custom attributes
MetaScheme qualifies a MetaName value. Any other attribute - microdata itemprop, media, lang, data-* - goes through AdditionalAttributes.
Adds <meta name="identifier" scheme="ISBN" ...>, a dark-mode theme-color with a media query, and a microdata itemprop tag.
Show Code
MetaTag.razor
<DwsMetaTag Name='MetaTagDemo_Attributes'>
<DwsMetaTagEntry Name='MetaTagDemo_Attributes_Scheme' MetaName='identifier' MetaScheme='ISBN' MetaContent='978-3-16-148410-0' />
<DwsMetaTagEntry Name='MetaTagDemo_Attributes_ThemeDark' MetaName='theme-color' MetaContent='#1b1f24' AdditionalAttributes='@_themeColorDarkAttributes' />
<DwsMetaTagEntry Name='MetaTagDemo_Attributes_ItemProp' MetaContent='DWS Blazor Component Library' AdditionalAttributes='@_itemPropAttributes' />
</DwsMetaTag>MetaTag.razor.cs
private readonly Dictionary<string, object> _themeColorDarkAttributes = new() { ["media"] = "(prefers-color-scheme: dark)" };
private readonly Dictionary<string, object> _itemPropAttributes = new() { ["itemprop"] = "name" };Limitations
- Your own HeadContent replaces the meta tags. Blazor's head shows only one HeadContent at a time, and DwsMetaTag renders through HeadContent. A plain
<HeadContent>elsewhere in the app therefore replaces the tags (or is replaced by them). Put other head content -<link>,<style>, ... - into a DwsMetaTag instead, as the "Multiple instances" example does. - No tags in the prerendered HTML of pages built on DwsPageBaseComponent. DwsPageBaseComponent does not prerender its Content (not even
<PageTitle>), so crawlers that do not run the app see none of that page's tags. A DwsMetaTag outside DwsPageBaseComponent (for example in the layout) is prerendered normally. - http-equiv="refresh" needs dws.js on statically rendered pages. The entry renders a marker that the script runs and cancels, because enhanced navigation keeps the document and a live refresh element would follow the user to other pages. Without the script there is no refresh for JavaScript-enabled visitors; visitors without JavaScript get the real element inside
<noscript>. In interactive render modes the entry runs the refresh itself and no script is needed. - Entries of all visible instances render in the head in registration order. Two instances that both set, for example,
descriptionproduce two tags; nothing is deduplicated.
Interface-Description
| Name | Typ | Default | Description |
|---|---|---|---|
| ValidationError | string? | null | DwsMetaTagEntry: why the parameter combination was rejected, e.g. MetaName and MetaProperty set together. Null when valid. |
| IsValid | bool | true | DwsMetaTagEntry: true when the parameters are valid and the entry renders. |
| Name | Typ | Default | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | DwsMetaTag: the DwsMetaTagEntry elements rendered into the document head. They are removed when the DwsMetaTag is hidden or disposed. Several DwsMetaTag instances combine. A plain HeadContent of your own replaces them, so put other head content (link, style) into a DwsMetaTag. |
| MetaName | string? | null | DwsMetaTagEntry: the name attribute (e.g. description, keywords). Requires MetaContent. |
| MetaProperty | string? | null | DwsMetaTagEntry: the property attribute used by Open Graph (e.g. og:title). Requires MetaContent. |
| MetaHttpEquiv | string? | null | DwsMetaTagEntry: the http-equiv attribute. Requires MetaContent. In interactive render modes 'refresh' is run by the entry and cancelled when it is hidden or disposed. |
| MetaContent | string? | null | DwsMetaTagEntry: the content attribute for MetaName, MetaProperty, MetaHttpEquiv or custom attributes. Not allowed with MetaCharset or MetaViewport. |
| MetaCharset | string? | null | DwsMetaTagEntry: the charset attribute. |
| MetaViewport | string? | null | DwsMetaTagEntry: shorthand for name='viewport' with this value as content. |
| MetaScheme | string? | null | DwsMetaTagEntry: the scheme attribute qualifying a MetaName value (e.g. ISBN). Only valid with MetaName. |
| AllowExternalRefreshUrl | bool | false | DwsMetaTagEntry: lets a refresh go to an http(s) URL on another origin. By default only the page's own origin is allowed; javascript:, data: and other schemes are always refused. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | Optional CSS class names. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The HTML ID attribute for the component. | |
| AdditionalAttributes | Dictionary<string, object> | Additional HTML attributes for the component's root element. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
