我正在学习服务器端。西装外套。
我已经阅读了一些项目的代码,发现了一些使用:
@{
}
Run Code Online (Sandbox Code Playgroud)
和一些使用:
@code{
}
Run Code Online (Sandbox Code Playgroud)
和其他使用:
@function{
}
Run Code Online (Sandbox Code Playgroud)
标记代码块。
我想知道这些之间的区别。谢谢你。
我正在使用 Blazor 的服务器端。
我想改变身体的CSS。
在 Jquery 中,我可以轻松地编写这样的代码:
$("body").css("overflow-y","hidden");
Run Code Online (Sandbox Code Playgroud)
但是,根据本教程(Blazor Change Validation default css class names)的说法,似乎我只能通过更改类名来更改 CSS。
穿越组件的时候太复杂了,尤其是body在所有组件的最上面。
我想知道是否有一种方法可以直接在 Blazor 中更改 CSS。谢谢你。
我正在 blazor 服务器端制作一个聊天室应用程序。
我想显示每个用户的在线状态。
现在我可以使用该OnAfterRenderAsync事件来获取用户已进入该页面。
exit通过https://docs.microsoft.com/en-us/aspnet/core/blazor/lifecycle?view=aspnetcore-3.1在 blazor 生命周期中似乎没有任何事件
有人说我可以使用该Dispose事件来实现它,而它确实有效。
更重要的是,我有一个疯狂的想法,即使用 window.onbeforeunloadjs事件来调用blazor方法。
我不知道哪一个最好。你能给我一个建议吗?谢谢你。
我正在通过 Blazor 服务器端制作聊天室应用程序。我想显示每个用户的在线状态。
我在如何在 blazor 服务器端关闭页面时获取事件中询问了如何在关闭页面时获取事件的问题?
现在看来这CircuitHandler是最好的选择。
当用户关闭页面时,我想在数据库中设置一个用户状态从在线到离线。而且,每个用户的主键暂时存储在index.razor.
但是现在OnCircuitClosedAsync(Circuit, CancellationToken)跑完之后,不知道怎么调用方法来实现这个(无法获取到Blazor前端的变量,也无法调用前端的Blazor方法)。
PS:这里是后端的代码:
using Microsoft.AspNetCore.Components.Server.Circuits;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace BlazorCircuitHandler.Services
{
public class CircuitHandlerService : CircuitHandler
{
public ConcurrentDictionary<string, Circuit> Circuits { get; set; }
public CircuitHandlerService()
{
Circuits = new ConcurrentDictionary<string, Circuit>();
}
public override Task OnCircuitOpenedAsync(Circuit circuit, CancellationToken cancellationToken)
{
Circuits[circuit.Id] = circuit;
return base.OnCircuitOpenedAsync(circuit, cancellationToken);
}
public override Task OnCircuitClosedAsync(Circuit circuit, CancellationToken cancellationToken)
{
Circuit circuitRemoved;
Circuits.TryRemove(circuit.Id, …Run Code Online (Sandbox Code Playgroud) 我想每 5 分钟将数据从内存数据库更新到关系数据库。
每个人都建议我使用IHostedServicefrom origin .net core 或其他一些第三方软件包,例如Hangfire.
而我认为它太麻烦了,因为它必须编码很多。
我有一个奇怪的想法,通过循环任务来实现它,例如:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace WebApplication3.Controllers
{
[Route("api/")]
public class TestController : Controller
{
public TestController()
{
Task.Run(() => {
while (true)
{
Console.WriteLine("123");//code something to transfer data to the database
Thread.Sleep(5000);
//Task.Delay(5000);
}
});
}
[Route("ABC")]
public void ABC()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
更重要的是,它是如此奇怪,如果我使用它就不会延迟,Task.Delay而如果我使用Thread.Sleep.
我想知道为什么没有人通过Taskof实现它System.Threading.Tasks?
也许这是一个愚蠢的问题,但我想找到原因。谢谢你。
我的网站在同一台服务器上使用hangfire 运行。
Hangfire 仪表板在本地运行良好。但是,当我http://localhost/hangfire/recurring在服务器计算机上访问时,它报告以下错误:
Unable to refresh the statistics: the server responded with 500 (Internal Server Error). Try reloading the page manually, or wait for automatic reload that will happen in a minute.
Run Code Online (Sandbox Code Playgroud)
我在 Chrome DevTools 上发现了问题:http://localhost/hangfire/stats 返回 500(内部服务器错误)。
很快我就找到了这方面的日志:
2021-05-29 15:35:55.6185|7|ERROR|Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery|An exception was thrown while deserializing the token. Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
---> System.Security.Cryptography.CryptographicException: The key {a2487e3b-0ba1-4f7f-9679-8721bb79278e} was not found in the key ring.
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] …Run Code Online (Sandbox Code Playgroud) 我想检查浏览器是否是 IE 并在剃刀页面中做一些事情。
我刚刚在剃刀页面中做了一个功能来做到这一点。
但是,我认为在每个razor页面中使用该功能检查浏览器是否为IE是多余的。对于独立用户,我只需要检查一次并设置一个IsIE = true / false的全局变量。其他页面将很容易知道,如果是IE。
问题是如何在剃刀页面中获取/设置全局变量?
谢谢你。
———————————————
致@Neville Nazerane,这里是检查是否是IE的函数:
@{
Boolean IsIE = false;
string UA = Context.Request.Headers["User-Agent"].ToString();
if (UA.Contains("Trident") || UA.Contains("MSIE"))
{
IsIE = true;
}
else
{
IsIE = false; ;
}
if (IsIE == true)
{
}
else
{
}
}
Run Code Online (Sandbox Code Playgroud) 我们知道,从 .net core 3.0 开始就有 ReadyToRun 编译选项。
有几个由.net core制作的dll。
我创建了一个WPF项目并引用了上面的所有dll。
现在我即将使用 ReadyToRun 发布项目,但有一个问题我不太确定。
当我只编译WPF项目时,编译器是否会使用ReadyToRun编译所有参考dll?
或者我必须在其项目中与ReadyToRun一一编译?
为什么我问这个问题,编译这么多目标时间不同的dll这么麻烦。我想找到一种快速的方法来做到这一点。
谢谢 。