我有这门课:
type Sample() =
member val test1 = "" with get,set
member val test2 = "" with get,set
// is something like the below constructor possible
new Sample(result1, result2) =
this.test1 <- "failed"
this.test2 <- "passed"
Sample()
Run Code Online (Sandbox Code Playgroud)
我尝试了几种不同的方法,但我无法让它发挥作用.
我希望asp.net标识表存在于我的数据库中,并且在我实际运行mvc应用程序并创建用户之前生成相应的相应代码优先模型,以便我可以针对这些类编写一些逻辑在手之前.有没有办法可以手动创建这些表/类与迁移?
我正在构建一个示例 razor 组件,但我的按钮 onclick 方法无法触发。当我单击按钮时,什么也没有发生。我什至在方法中放置了一个断点,以查看它是否捕获了它没有捕获的。该组件确实呈现,但正如我所说,单击按钮时,LoginUser 方法根本没有运行。
剃须刀组件页面:
<div class="text-center">
<Login FieldsetAttr="fieldsetAttr" UsernameAttr="usernameAttr" PasswordAttr="passwordInput"
ButtonAttr="buttonAttr" ButtonText="Sign In" SignInManager="SignInManager"
InvalidAttr="invalidAttr" />
</div>
@code {
Dictionary<string, object> fieldsetAttr =
new Dictionary<string, object>()
{
{"class", "form-group" }
};
Dictionary<string, object> usernameAttr =
new Dictionary<string, object>()
{
{"class", "form-control" },
{"type", "text" },
{"placeholder", "Enter your user name here." }
};
Dictionary<string, object> passwordInput =
new Dictionary<string, object>()
{
{"class", "form-control" },
{"type", "password" }
};
Dictionary<string, object> buttonAttr =
new Dictionary<string, object>()
{
{"class", …Run Code Online (Sandbox Code Playgroud) 我正在为 Asp.net 核心 3.0 Blazor 服务器端应用程序构建示例登录 razor 组件。每当代码到达 SignInAsyc 方法时,它似乎只是挂起或锁定,因为代码停止进一步执行。我还尝试通过使用 PasswordSignInAsync 方法来切换逻辑,这给了我完全相同的结果。所有代码都将在该方法之前执行,但在执行该语句时会冻结。我在这里缺少什么?
Razor 组件页面:
<div class="text-center">
<Login FieldsetAttr="fieldsetAttr" UsernameAttr="usernameAttr" PasswordAttr="passwordInput"
ButtonAttr="buttonAttr" ButtonText="Sign In" InvalidAttr="invalidAttr" />
</div>
@code {
Dictionary<string, object> fieldsetAttr =
new Dictionary<string, object>()
{
{"class", "form-group" }
};
Dictionary<string, object> usernameAttr =
new Dictionary<string, object>()
{
{"class", "form-control" },
{"type", "text" },
{"placeholder", "Enter your user name here." }
};
Dictionary<string, object> passwordInput =
new Dictionary<string, object>()
{
{"class", "form-control" },
{"type", "password" }
};
Dictionary<string, object> buttonAttr …Run Code Online (Sandbox Code Playgroud) 我正在尝试在服务器端 Blazor 应用程序中显示倒数计时器。我的代码在 F# 和 C# 中。该代码有些工作,但计时器永远不会按预期停止,并且计时器显示偶尔不会呈现所有数字。这是我第一次尝试 Blazor 服务器端应用程序。我不确定问题是异步问题、计时器问题还是渲染问题。
这是我的代码:
F#
let private setTimer countDown timeEvent =
let timer = new Timer(float countDown * float 1000)
let mutable time = 0
time <- countDown
timer.Elapsed.Add(fun arg ->
time <- time - 1
if time = 0
then
timer.Stop()
timer.Dispose()
else
()
timeEvent arg
)
timer.AutoReset <- true
timer.Start()
let setTimerAsync countDown timeEvent = async{
setTimer countDown timeEvent
do! Async.Sleep (countDown * 1000)
}
type Timer (countDown) =
member val CountDown …Run Code Online (Sandbox Code Playgroud) 我的自定义中间件似乎与我的 blazor 服务器端页面发生了某种冲突。简短的示例中间件检查 bool 状态,如果 true 重定向到开箱即用的 blazor 模板提供的计数器页面。如果没有将中间件插入管道,当您单击按钮时,计数器页面可以正常工作,但是一旦将中间件放置在管道中,按钮就不再起作用,因为它不会增加计数。我已经将自定义中间件放在 app.UseEndpoints 中间件之前,虽然看起来它放在哪里并不重要,因为无论它的顺序如何,它都不起作用。 为什么我的自定义中间件破坏了 blazor 服务器- 侧页无法正常运行?
中间件:
class CheckMaintenanceStatusMiddleware
{
private readonly RequestDelegate _next;
public CheckMaintenanceStatusMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var statusCheck = true;
if(statusCheck && context.Request.Path.Value != "/counter")
{
context.Response.Redirect("/counter");
}
else
{
await _next.Invoke(context);
}
}
}
public static class CheckMaintenanceStatusMiddlewareExtension
{
public static IApplicationBuilder UseCheckMaintenanceStatus(this IApplicationBuilder builder)
{
return builder.UseMiddleware<CheckMaintenanceStatusMiddleware>();
}
}
Run Code Online (Sandbox Code Playgroud)
启动文件中的配置方法:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ …Run Code Online (Sandbox Code Playgroud) 有人可以向我描述如何使用asp.net身份删除角色.我尝试了以下,但它没有工作,我收到一个指定方法不支持错误:
public async Task DeleteRole(string role)
{
// delete role
var roleStore = new RoleStore<IdentityRole>(new Context());
await roleStore.DeleteAsync(new IdentityRole(role));
}
Run Code Online (Sandbox Code Playgroud)
不确定这是指我的异步逻辑,还是特别是asp.net身份本身.然而,有人可以告诉我如何使这项工作正确.目前,asp.net的新身份系统几乎没有可用的文档.
这是代码:
type Advertisement() =
member val Photos = seq<images> with get,set
Run Code Online (Sandbox Code Playgroud)
但是这会返回属性Photos as的函数签名
seq<images> -> seq<images>
Run Code Online (Sandbox Code Playgroud)
我只想要属性来表示一系列图像
seq<images>
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我试图了解新的asp.net身份2.0是如何工作的,但是由于文档很少,我遇到了很多绊脚石.
我在下面的代码基于我读过的几个教程:
public class CustomRole : IdentityRole<string, CustomUserRole>
{
public CustomRole() { }
public CustomRole(string name) { Name = name; }
}
public class CustomUserRole : IdentityUserRole<string> { }
public class CustomUserClaim : IdentityUserClaim<string> { }
public class CustomUserLogin : IdentityUserLogin<string> { }
// define the application user
public class ApplicationUser : IdentityUser<string, CustomUserLogin, CustomUserRole,
CustomUserClaim>
{
[Required]
public bool IsActive { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined …Run Code Online (Sandbox Code Playgroud) 我试图让下面的代码在F#异步工作流中工作,但我在表达式中收到错误"Unexpected symbol'}'".我对F#和async都很新.我在这里想念的是什么
let someFunction (req : HttpRequestMesssage) a b =
// code
async{
let! readToProvider =
req.Content.ReadAsMultipartAsync(provider)
|> Async.AwaitIAsyncResult
} |> Async.RunSynchronously
req.CreateResponse(HttpStatusCode.OK)
Run Code Online (Sandbox Code Playgroud)