天天看點

.Net5.0 Blazor 高頻代碼

對象序列化成Json:

string jsonString = JsonSerializer.Serialize(weatherForecast);
           

在服務端擷取使用者請求的Url位址:

@using Microsoft.AspNetCore.Http.Extensions
@Context.Request.GetEncodedUrl() //Use for any purpose (encoded for safe automation)
@Context.Request.GetDisplayUrl() //Use to display the URL only
           

在Controller中擷取已驗證使用者ID:

if (user != null && user.Identity.IsAuthenticated)
         userId = Convert.ToInt64(user.FindFirst(ClaimTypes.NameIdentifier).Value);