问题标签 [blazor-webassembly]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1406 浏览

blazor - How can I customize Blazor WebAssembly Msal auth to store token in localStorage instead of sessionStorage?

Context

I am working off the Secure an ASP.NET Core Blazor WebAssembly standalone app with Azure Active Directory B2C guide to enable client-side authentication in my Blazor WebAssembly app (there is no server-side component, the entire app runs in the browser). The setup works as expected, I am able to redirect users to the AD B2C user flow, log in, and redirect back into my app with the user properly authenticated.

Problem

The default authentication behavior persists the JWT token retrieved from AD B2C inside of sessionStorage, which clears as soon as the browser window is closed. I would like to customize this default functionality to instead persist the token to localStorage for longer-lived auth sessions—I'd love to keep the user logged in to subsequent visits after they close the browser window. The docs don't seem to provide any info on how I might accomplish this.

I've also taken a look at the Additional Scenarios docs to under how the RemoteAuthenticatorView might be customized, but was unable to find any info related to how these tokens are stored and retrieved.

I appreciate any guidance on this!

0 投票
1 回答
276 浏览

protobuf-net - 如何使用 Grpc 和 protobuf-net 在 Blazor Web Assembly 中注入依赖项

我正在使用 protobuf-net 使用 Grpc 构建 Web Assembly Blazor 来处理服务。我正在尝试以这种方式注入我想要的服务:

然后,我将我认为应该是依赖项的内容注入到 razor 组件中:

但我得到这个错误:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer [100] 未处理的异常呈现组件:无法为“Customer_Create”类型的属性“客户端”提供值。没有“ICustomerService”类型的注册服务。

非常感谢这里的任何帮助!

0 投票
1 回答
244 浏览

blazor - Blazor 或某些 NuGet 包是否支持或扩展嵌套路由的路由?

想象一下,我有一个在线销售和订单处理应用程序。我有客户、发票、发票项。客户对他们最后一个订单中的某件商品有疑问,并希望将链接发送给他们的销售代表。

Blazor 如何处理这种 URL 应该类似于...的情况

https://myapp.com/customer/12345/Invoice/234/InvoiceItem/4

Blazor 路由引擎可以做到这一点吗?

我已经阅读了多篇博客文章和路由似乎停止: /page/{parameter} 而我真的很喜欢 /page/{parameter}/control/{parameter}/control/{parameter}/etc...

0 投票
1 回答
1871 浏览

c# - 如何使用?或者 ??有条件地呈现 Blazor 模板?

我想简化以下

???.

可能吗?

试图

我在下面的尝试

  • @Template?.BeginInvoke()
  • @{Template==null? @Template : <span> No data to display! </span>}
  • @(Template??<span> No data to display! </span>)

产生红色波浪线。

编辑

我想我需要提交我想要简化的真实场景。

我不想将传入的值缓冲到****Template具有私有字段的属性中,在将它们(字段)呈现为 HTML 之前对字段进行预处理。换句话说,@code{}指令中不允许有额外的代码。

0 投票
1 回答
640 浏览

blazor - 如何从 Razor 页面(Blazor WebAssembly)中的 launchSettings.json 文件访问属性?

我在 launchSettings.json 文件中创建了这些属性。现在我需要访问 Student.razor 页面中的 API-1 和 API-2 值。我试着像这样使用它..

0 投票
2 回答
841 浏览

asp.net-core - 使用 gRPC-Web 和 protobuf-net 在工作服务中添加新方法时出现异常

我收到以下异常:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常呈现组件:“DefaultProxyCache 1' threw an exception. System.TypeInitializationException: The type initializer for 'DefaultProxyCache1”的类型初始化程序引发异常。---> System.ArgumentException:无效的通用参数参数名称:typeArguments at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.MakeGenericMethod_impl(System.Reflection.RuntimeMethodInfo,System.Type[]) at System.Reflection.RuntimeMethodInfo .MakeGenericMethod(System.Type[] methodInstantiation) <0x342def8 + 0x000d6> in :0 at ProtoBuf.Grpc.Internal.ContractOperation.TryGetClientHelper() [0x0001b] in //src/protobuf-net.Grpc/Internal/ContractOperation.cs: 291 在 ProtoBuf.Grpc.Internal.ProxyEmitter.EmitFactory[TService] (ProtoBuf.Grpc.Configuration.BinderConfiguration binderConfig) [0x00477] 在 //src/protobuf-net.Grpc/Internal/ProxyEmitter.cs:238 在 ProtoBuf.Grpc.Internal.ProxyEmitter.CreateFactory[TService] (ProtoBuf.Grpc.Configuration.BinderConfiguration binderConfig) [0x0006d] in //src/protobuf-net .Grpc/Internal/ProxyEmitter.cs:123 at ProtoBuf.Grpc.Configuration.ClientFactory+DefaultProxyCache`1[TService]..cctor()[0x00000] in //src/protobuf-net.Grpc/Configuration/ClientFactory.cs: 81

我的项目使用 gRPC-Web、Blazor Web 程序集和 protobuf-net

这是我的服务合同:

实现是:

至于数据合同:

和,

在我返回服务中的客户列表之前,但我意识到我需要一个类来对消息进行建模,以便 protobuf-net 能够序列化,这就是 CustomerResultSet 的原因。尽管如此,它仍然无法正常工作。非常感谢任何帮助

0 投票
4 回答
7473 浏览

c# - 如何在 Blazor WebAssembly-PWA 中运行离线数据库使用?

我有一个Blazor WebAssembly ASP.NET Core hosted - PWA应用程序并想离线运行它。该数据库目前使用 SQLite 和 EF-Core 构建。是否可以添加离线功能?我已经阅读过IndexedDB但实际上并不知道如何将其实施到项目(客户端)中。或者是否有任何用于此支持的 NuGet 包?

我想为项目带来的功能是 -跟踪本地更改并在数据库再次联机时将其提取到数据库。

0 投票
3 回答
2323 浏览

c# - Blazor WebAssembly 项目,Intellisense 弹出错误:找不到类型或命名空间名称“App”

我正在尝试使用 Blazor WebAssembly。我创建了一个项目,代码是L

正如我在代码中评论的那样,智能感知未找到 App 并显示错误。我不能在“App”一词上使用 f12(未找到)。我可以构建和启动项目,但我想正确清理它。

我关注了这个线程:Blazor 找不到类型或命名空间名称“App”(您是否缺少 using 指令或程序集引用?)但它没有修复它。

我的 IDE 是 Visual Studio Community:Microsoft Visual Studio Community 2019 Version 16.6.2 和 dotnet --version 给出:5.0.100-preview.6.20318.15

非常感谢。

0 投票
0 回答
141 浏览

identityserver4 - 使用 Identity Server 保护 ASP.NET Core Blazor WebAssembly 托管的应用程序

我有一个使用 blazor 托管模板的项目。无需在 iis 服务器中进行身份验证即可正常工作。但是在我使用这种方法添加身份验证之后, iis 服务器给出了这个错误。

HTTP 错误 500.30 - ANCM 进程内启动失败

我该如何解决。这是我第一次使用身份服务器。我不知道修复这个错误。任何评论都将适用。

更新

此日志由应用程序生成

谢谢

0 投票
0 回答
126 浏览

c# - Blazor WASM 可以调试但不能发布

我使用 blazor 创建了一个在调试状态下正确运行的应用程序,但我无法发布它。在发布状态下,我收到以下错误:

我不知道发生了什么。谁能帮我?谢谢!