嗨,堆栈溢出!
我正在使用客户端 Blazor,并且偶然发现了一个关于使用字符串和点 (.) 进行路由的棘手部分。我希望从管理控制页面路由到具有以下路由的页面:@page "/ManageGradingExamResults/{StudentEmail}". 我用这个请求进行了测试:https://localhost/ManageGradingExamResults/1234@high.school.nz,但我没有找到。如果我将剃刀路线更改为@page "/ManageGradingExamResults/{*StudentEmail}"我最终会出现以下异常:System.InvalidOperationException: Invalid template 'ManageGradingExamResults/{*StudentEmail}'. The character '*' in parameter segment '{*StudentEmail}' is not allowed.. 由于 cshtml 页面的相似性,我尝试了这一点。
我发现我可以用整数路由,但对字符串没有运气。我也遇到过这个Microsoft 文档,它解释了路由参数并在我的页面路由中建议了 **。这允许我进入我的页面,但是我需要使用 ? 在我的电子邮件请求之前,页面没有加载我的数据,因为我可以看到它没有将参数拉入我的变量中。任何有关客户端 Blazor 路由的建议或帮助将不胜感激!
请求代码:
NavigationManager.NavigateTo($"/ManageGradingExamResults/?{student.Email}");
Run Code Online (Sandbox Code Playgroud)
请求网址:
https://localhost/ManageGradingExamResults/?1234@high.school.nz
Run Code Online (Sandbox Code Playgroud)
剃刀页面路线:
@page "/**ManageGradingExamResults/{StudentEmail}"
@page "/ManageGradingExamResults"
Run Code Online (Sandbox Code Playgroud)
我的变量:
@code
{
[Parameter]
public string StudentEmail { get; set; }
...
Run Code Online (Sandbox Code Playgroud) 我目前正在学习 asp.net core 和 blazor,并且遇到了一个文档很少的问题。我有一个服务器端 Blazor 应用程序,并且正在进行身份验证以使用本地存储和 ServerAuthenticationStateProvider。此代码基于本指南,这是我当前对状态提供程序的实现:
MyAuthenticationStateProvider.cs
namespace BlazorApp
{
public class MyAuthenticationStateProvider : ServerAuthenticationStateProvider
{
private readonly HttpClient _httpClient;
private readonly ILocalStorageService _localStorage;
public MyAuthenticationStateProvider(HttpClient httpClient, ILocalStorageService localStorage)
{
_httpClient = httpClient;
_localStorage = localStorage;
}
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
var savedToken = await _localStorage.GetItemAsync<string>("authToken");
if (string.IsNullOrWhiteSpace(savedToken))
{
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
}
var user = new ClaimsPrincipal(new ClaimsIdentity(ParseClaimsFromJwt(savedToken), "jwt"));
return new AuthenticationState(user);
}
public void MarkUserAsAuthenticated(string token)
{
var authenticatedUser = …Run Code Online (Sandbox Code Playgroud) 我是编程世界的新手,我想用这段代码来移动一个小舵机:
# Servo Control
# Servo Control
import time
import wiringpi
# use 'GPIO naming'
wiringpi.wiringPiSetupGpio()
# set #18 to be a PWM output
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)
# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)
delay_period = 0.01
while True:
for pulse in range(50, 250, 1):
wiringpi.pwmWrite(18, pulse)
time.sleep(delay_period)
for pulse in range(250, 50, -1):
wiringpi.pwmWrite(18, pulse)
time.sleep(delay_period)
Run Code Online (Sandbox Code Playgroud)
当我在空闲状态下运行这段代码时,出现以下错误:
Traceback (most recent call last):
File "/home/pi/servo.py", line 3, in <module>
import wiringpi
ImportError: No …Run Code Online (Sandbox Code Playgroud) asp.net-core ×2
c# ×2
blazor ×1
importerror ×1
module ×1
python-3.x ×1
raspberry-pi ×1
routing ×1
wiringpi ×1