Skip to content

Access AuthenticationState in Blazor Server to update components in a single place #25908

Discussion options

You must be logged in to vote

If you want to share common functionality across all pages, here are a couple of options:

Option 1: Common base class

If you create a C# class that inherits from ComponentBase, then you can make all your .razor components inherit from your custom class via:

@inherits MyCustomBaseClass

Then, in MyCustomBaseClass, you can override lifecycle events like OnInitializedAsync and put your common logic there.

Option 2: In the router

If you don't want to use inheritance, then you could use something like the following in App.razor:

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <MyRoutingMiddleware>
            <RouteView RouteData="@routeData" DefaultLayout=

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by SteveSandersonMS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants