Gray Wolf Corporation

Migrating Blazor Identity from .Net 7 to 8

Workaround from github

The underlying table structures and authentication logic from MS Identity haven't changed from 7 to 8, but pretty much everything else has.

Identity is now under the Account folder in Components, rather than an Area in .Net 7.

The above github issue explains that Identity pages need to be static to access HttpContext. The GA release was supposed to force all Identity pages to static, regardless of what was specified in @rendermode. This might work in a clean .Net 8 project, but caused all kinds of problems when I was migrating.

I created a temp .Net 8 Blazor web app project with authentication to see all the changes needed in program.cs. I also updated app.settings to confirm the underlying db did not need to be changed.

The workaround is to set @rendermode=null when navigating to any Account pages.

App.razor

@inject IHttpContextAccessor HttpContextAccessor
<html lang="en">
<head>
    <HeadOutlet @rendermode="@RenderModeForPage" />
</head>
<body>
<Routes @rendermode="@RenderModeForPage" />
</body>
</html>
@code {
    private HttpContext HttpContext => HttpContextAccessor.HttpContext;

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

blazor-identity

Check out the github issue to see further formatting tips for the account pages.

An unhandled error has occurred. Reload 🗙