liveBook · Manning

Razor attribute

As explained in Building Distributed Applications that Work

A Razor attribute is metadata attached to a Razor component or page that influences its framework-defined behavior.

A Razor attribute attaches framework-defined behavior to a component or page. On an online shop’s order-tracking page, an authorization attribute requires users to be authenticated before they can access the page. section 8.3

@attribute [Microsoft.AspNetCore.Authorization.Authorize]

Place this attribute in OrderTracking.razor to require authentication for the page. section 8.3

First, configure authentication and add authorization services. Run authentication and authorization middleware before endpoint registration. If an unauthenticated user opens the protected page, the middleware redirects them to the identity provider’s login page using the configured Authority; the page needs no redirect code. Product browsing can remain available without registration, while placing orders requires authentication. section 8.3

How Building Distributed Applications that Work covers it

How deep it goes
Shows the attribute and its required service and middleware setup, but does not explain attribute internals.
Examples
Uses an online shop’s OrderTracking.razor page and contrasts it with publicly browsable products.
What it assumes
Assumes configured authentication and adds authorization services and middleware before applying the attribute.
What you can do after
Apply it via Razor to require authentication on a page without writing login-redirect code.
How it connects
Connects Razor pages with authorization, authentication middleware, OpenID Connect, and identity-provider redirects.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Distributed Applications that Work. The section links point to the parts of the book it draws on.