【问题标题】:Blazor component in identity razor page身份剃须刀页面中的 Blazor 组件
【发布时间】:2020-02-01 03:42:03
【问题描述】:

按照 Visual Studio Tempalte 中的建议,我有一个带有身份验证设置的服务器端 Blazor 应用程序。然后我添加了身份脚手架项目。不,我尝试将剃须刀组件添加到登录屏幕,以便我可以将所有内容保持在相同的设计中。

在页面本身我添加了这个:

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

现在,由于身份页面在IdentityHostingStartup.cs 中设置的自己的进程中运行(基于 ScaffoldingReadme),我尝试在那里添加 Blazor 设置内容:

        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();
        });
    }
}

但是一旦我这样做了,当我尝试在 programm.cs 中解析我的数据库上下文时,我就会得到一个空指针异常。有趣的是,当我在 IdentityStartup 中只有空方法体时,也会发生这种情况。我还尝试将所有数据库初始化代码移动到启动中以避免空指针,但随后该站点将无法启动。 我必须以不同的方式或其他地方进行设置吗?

【问题讨论】:

  • 您找到解决方案了吗?
  • 很遗憾,没有。
  • 糟糕,我也有类似的问题。为它创建了我自己的帖子,因为它有一些其他错误/问题 (stackoverflow.com/questions/62203126/…)。最后,你是不是只使用纯 CSS / cshtml 标记而不是组件?
  • 是的,我最终生成了 Identity Razor 页面并相应地设置了它们的样式。这有点不幸,因为我必须为此使用不同的框架(因为 Blazor 显然不能工作)。所以看起来略有不同。

标签: asp.net-identity blazor blazor-server-side


【解决方案1】:

您缺少一些用于配置 DBContext 的代码。

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

更多详情Configuring a DbContext

【讨论】:

  • 请注意,此时我没有进行任何数据库访问。 blazor 组件只是显示一个文本。
猜你喜欢
  • 2020-05-22
  • 2020-08-11
  • 2020-04-30
  • 1970-01-01
  • 2021-06-28
  • 2022-01-10
  • 2020-02-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多