Cookie consent
Ask before any cookie that isn't essential: a notice until the visitor chooses, a settings page, and a way for your code to check.
Preview
Cookies on MyApp
We use essential cookies to keep you signed in. With your OK, we'd also use analytics cookies to learn how MyApp is used. Cookie policy
Add it to your project
-
Sign in once on this machine
izzy loginThe account is free. Create a free account
-
Add the block
izzy add block cookiesWrites Components/Blocks/CookieNotice.razor, Components/Pages/Cookies.razor and Consent.cs and places it on MainLayout, before </AppShell>.
Settings
Each setting is a flag on izzy add. The flag syntax isn't final; for now it looks like this:
izzy add block cookies | Name | Type or choices | Default | Description |
|---|---|---|---|
SettingsRoute | text | cookies | The settings page's address, without the leading slash: the footer's Cookie settings link goes here. |
PolicyHref | text | privacy | Where "Cookie policy" goes, such as the privacy page from izzy add block legal. |
Name | text | CookieNotice | The notice's component name. |
PageName | text | Cookies | The settings page's component name. |
Into | text | Components/Layout/MainLayout.razor | The layout the notice is placed in, at the end of its AppShell. When every page runs in the browser, it goes in App.razor after Routes instead, rendered on the server. |
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Everything | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Accessibility
- The notice is a region named by its heading, so screen readers can find it; it doesn't block the page or take focus.
- Reject analytics and Accept all are the same size and style, so rejecting is as easy as accepting.
- On the settings page each switch is named by its category; Essential is on and can't be turned off, and says so.
Components used
- Card: Groups media, a header, body sections, actions and a footer in a box.
- Heading: Renders headings 1 to 6, with fluid sizes and section links.
- TextBlock: Sets paragraphs, captions and labels in the library's text styles.
- Anchor: Renders a text link, internal or external.
- Button: Submits or resets a form, follows a link or runs C#.
- Stack: Lays out its children in a row or a column, changing with the screen width.
- Grid: Lays out its children in columns set by breakpoint, by minimum width or by template.
- Spacer: Pushes the rest of a row to the end.
- Form: Posts its fields on static pages and validates them live on interactive pages.
- Switch: Shows an on/off switch that posts like a checkbox.
- Row: Lines up buttons, badges or fields side by side, with a gap between them.
- Column: Stacks fields, cards or text from top to bottom, with even spacing.