How to run multiple Blazor apps in single website(如何在一个网站上运行多个Blazor应用)
问题描述
我要创建一个网站,其中某些子功能将拆分到多个Blazor项目中。 所以主站点是一个Blazor应用程序,但是/private和/shop是单独的Blazor应用程序,用户需要注册和登录才能访问功能。 由于主网站应该有所有网站通用的导航栏(有登录和注册按钮),如何在Blazor应用程序之间通信?
如果我在主站点上设置身份验证并使用主站点中的AppState存储值,则在/Private中运行的子应用如何访问此数据(例如,is Logging in或用户名数据)。
推荐答案
这看起来很有希望:Blazor with multiple apps
我也一直在试图弄清楚如何做到这一点。上面的例子展示了如何在一个解决方案中将两个客户端Blazor应用程序与单个服务器端Blazor应用程序链接起来。我从该示例中获得的主要内容是在服务器端应用程序启动时向配置添加的内容。
app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/FirstApp"), first =>
{
first.UseBlazorFrameworkFiles("/FirstApp");
first.UseStaticFiles();
first.UseRouting();
first.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("FirstApp/{*path:nonfile}", "FirstApp/index.html");
});
});
app.MapWhen(ctx => ctx.Request.Path.StartsWithSegments("/SecondApp"), second =>
{
second.UseBlazorFrameworkFiles("/SecondApp");
second.UseStaticFiles();
second.UseRouting();
second.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("SecondApp/{*path:nonfile}", "SecondApp/index.html");
});
});
希望这对您有帮助。
这篇关于如何在一个网站上运行多个Blazor应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在一个网站上运行多个Blazor应用


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01