4
votes

I have a server side Blazor Application with Authentication setup as suggested in the Visual Studio Tempalte. I then added the identity scaffolding items. No I try to a razor component to the login screen, so that I can keep everything in the same design.

On the page itself I added this:

<script src="~/_framework/blazor.server.js"></script>
<Login>
    @(await Html.RenderComponentAsync<ApplySupportTool.Blazor.Pages.Shared.Login>(RenderMode.Server))
</Login>

Now since the Identity Pages run in their own processes (based on the ScaffoldingReadme) which is setup in the IdentityHostingStartup.cs I tried to add the Blazor Setup things there:

        builder.ConfigureServices((context, services) => { 
        });

        builder.UseStartup<IdentityStartup>();

public class IdentityStartup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddServerSideBlazor();
    }

    public void Configure(IApplicationBuilder app)
    {
        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
        });
    }
}

But as soon as I do that, I get an Null Pointer Exception when I try to resolve my DB Context in the programm.cs. Interesstingly this happens as well when I have just the empty method bodies in the IdentityStartup. Also I tried to move all DB initialization code into the startup to avoid the null pointer, but then the site just won't start. Do I have to set this up differently or somewhere else?

1
Did you ever found the solution? - Nicolas
Unfortunately not, no. - NPadrutt
to bad, I have a similar problem as well. Created my own post for it since it has some other errors / problems (stackoverflow.com/questions/62203126/…). In the end, did you just use plain CSS / cshtml markup instead of components? - Nicolas
Yeah, I ended up generating the Identity Razor Pages and styled those eaccordingly. It’s kinda unfortunate, since I have to use a different framework for that (since the Blazor one doesn’t work obviously). So it looks slightly different. - NPadrutt

1 Answers

0
votes

You lack some code for config DBContext.

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<BloggingContext>(options => options.UseSqlite("Data Source=blog.db"));
}

More details in Configuring a DbContext