11

I have been playing around with the new .Net 8 Blazor templates and ran into a problem with Identity and setting a global InteractiveServer render mode. The change I made was in the App.Razor file to the :

<Routes @rendermode="InteractiveServer" />

The reason I added this was because I was also attempting to get MudBlazor integrated and this was required for it to run properly (as far as I could tell at least). MS does list the ability to do this via docs as well so appears to be a legitimate choice to make to set this global render mode.

The issue I then faced was with any page using the AccountLayout component e.g. Login, Register, ResetPassword etc because it loops on this part:

if (HttpContext is null)
{
    // If this code runs, we're currently rendering in interactive mode, so there is no HttpContext.
    // The identity pages need to set cookies, so they require an HttpContext. To achieve this we
    // must transition back from interactive mode to a server-rendered page.
    NavigationManager.Refresh(forceReload: true);
}

As it's globally set it's always hit so goes into an endless navigation loop. I attempted to set the account layout and/or account pages to use a rendermode of null, default, static etc but they don't seem to be valid options nor can I find any examples of anyone doing this.

So my question is, does anyone know of a way to either set default/static on a component for render mode OR know of a way to get MudBlazor working in .net 8 project without using global interactive mode? I have obviously tried setting the rendermode to interactive on relevant pages using mudblazor.

1 Answer 1

17

I have found that this is currently an issue that appears to be getting fixed by MS. Within the issues I did find a workaround for now within this raised issue: https://github.com/dotnet/aspnetcore/issues/51476

Essentially changing the rendermode globally in app.razor based on the url:

<body>
    <Routes @rendermode="RenderModeForPage" />
    <script src="_framework/blazor.web.js"></script>
    <script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>

@code {
    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;

    private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/Account") ? null : InteractiveServer;
}

Can confirm I have tried this and have Identity pages and MudBlazor working on other pages as originally intended. At least it appears future templates should already contain the resolution for this.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! I as a Blazor Noob lost so many hours on this! Saves my project. Really appreciate.
This just removes interactivity on any page that starts with /Account for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.