我仍在学习 blazor 并想在其中制定一些解决方案,但要求是使用 Windows 之类的东西,例如 Windows 身份验证(用户登录就足够了)我知道 Windows 身份验证现在尚未实现/可用 - 将来会吗?
所以场景是:
- 在浏览器中运行 wasm
-实施
public class MyAuthStateProvider: AuthenticationStateProvider
Run Code Online (Sandbox Code Playgroud)
在
Task<AuthenticationState> GetAuthenticationStateAsync()
Run Code Online (Sandbox Code Playgroud)
-在那里获取Windows用户名(如何!?)
-使用此用户名向 api 发布一些帖子,从 api 获取现有数据库中的所有用户信息 + 令牌以供下一次 api 调用
-将其归还给 wasm 并离开。
有人可以给我指出方向吗?我搜索了很多,但大多数解决方案都是由于服务器端 blazor - 我需要它 wasm。我还发现在服务器端实现新的自定义授权、自定义注册等很多 - 我已经拥有用户的数据库。
或者应该以完全不同的方式制作?
感谢致敬
我想在我的服务中编写一个函数,处理生成动态组件到某些 viewchild 引用中...
我试过像
public GenerateDynamicComponent(ComponentName: string,viewContainerRef: ViewContainerRef, data?: any) {
switch (ComponentName.toUpperCase()) {
case 'DYNAMICFORMS':
const componentFactory = this.resolver.resolveComponentFactory(DynamicFormsComponent);
const formref = viewContainerRef.createComponent(componentFactory);
formref.instance.Data = data;
return formref;
break;
default:
return null;
}
Run Code Online (Sandbox Code Playgroud)
它确实工作得很好,但我不想使用这个开关并通过字符串发送这个组件名称
所以它需要像
public GenerateDynamicComponent<T>(viewContainerRef: ViewContainerRef,data?: any ) {
const componentFactory = this.resolver.resolveComponentFactory<T>(typeof T);
const formref = viewContainerRef.createComponent(componentFactory);
formref.instance.Data = data;
return formref;
}
Run Code Online (Sandbox Code Playgroud)
但当然这不起作用,因为 typeof T <> 组件类型...是否可以这样做或者需要像第一个示例中那样?
多谢!
我在 blazor 中构建一些动态表单生成器,我对这部分有疑问
@using Microsoft.AspNetCore.Components.CompilerServices
@using System.Text.Json
@using System.ComponentModel.DataAnnotations
@typeparam Type
<EditForm Model="@DataContext" OnValidSubmit="OnValidSubmit">
<DataAnnotationsValidator/>
@foreach (var prop in typeof(Type).GetProperties())
{
<div class="mb-3">
<label for= "@this.idform.ToString()_@prop.Name">@Label(@prop.Name) : </label>
@CreateStringComponent(@prop.Name)
@if (ShowValidationUnderField)
{
<ValidationMessage For = "@(()=> @prop.GetValue(DataContext))"></ValidationMessage>
}
</div>
}
@code {
[Parameter] public Type? DataContext { get; set; }
[Parameter]
public EventCallback<Type> OnValidSubmitCallback { get; set; }
[Parameter]
public bool ShowValidationSummary { get; set; } = false;
[Parameter]
public bool ShowValidationUnderField { get; set; } = true;
}
Run Code Online (Sandbox Code Playgroud)
所以我收到这个错误 …