我有一个使用 Identity 进行身份验证的 Blazor WASM 应用程序,该应用程序在周五运行良好。昨晚我去进行更改,在 Azure 中运行的应用程序和在我的计算机上本地运行的应用程序在启动后都开始出现异常。从一切正常运行到现在,环境或代码库没有任何变化。
The app runs, redirects to the login page, the get is processed fine on the server but throws an exception on the first line of markup in the .cshtml file (assuming because it is failing to encrypt the content at that point):
An unhandled exception occurred while processing the request. CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, string additionalMessage) …
我目前正在尝试在 blazor WASM 中异步调用一个昂贵的方法,同时不阻塞 UI 线程。
根据这个问题的回答,这是不可能的。然而,这些可以追溯到几年前,根据WebAssembly 路线图,现代浏览器支持线程。
另外,我可以await在不阻塞 UI 线程的情况下调用函数,只要函数是自下而上等待的。
在下面的代码片段中,单击按钮Foo将导致 UI 在执行操作时挂起几秒钟,但单击按钮Bar将在后台处理类似(但可等待)的操作,同时保持 UI 响应。
如果 WebAssembly 不支持多线程,为什么第二个选项似乎适用于多线程?如果它确实支持多线程,为什么第一个选项会阻塞 UI?
@page "/asynctest"
<div class="row">
<div class="col">
@DisplayValue
</div>
<div class="col">
<button type="button" @onclick="OnClickFoo">Foo</button>
</div>
<div class="col">
<button type="button" @onclick="OnClickBar">Bar</button>
</div>
</div>
@code{
private string DisplayValue = "";
private double Result;
private async Task OnClickFoo(EventArgs e)
{
DisplayValue = "Working...";
Result = await Task.Run(() => Frobnicate()); // Blocks UI thread
DisplayValue …Run Code Online (Sandbox Code Playgroud) 我对如何使用需要注入对象的 Razor 类库感到困惑。我创建了一个新的剃刀类库项目。没有program.cs 文件,因此没有WebAssemblyHostBuilder 可以添加服务?如何将依赖项注入到组件中?
尝试在服务器端控制器中调用 API 方法时出现以下错误
我在这里做错了什么。
此外,我还收到“抱歉,调用 /swagger 时此地址没有任何内容”
索引剃刀
var httpclient = new HttpClient();
httpclient.BaseAddress = new Uri("https://localhost:7191/");
var result = httpclient.GetStringAsync($"api/Account/LoginUser?userName={userName}&Email={Email}");
Run Code Online (Sandbox Code Playgroud)
我的控制器
using BlazorChatApp.Shared;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace BlazorChatApp.Server.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class AccountController : ControllerBase
{
[HttpGet]
[AllowAnonymous]
public async Task<ActionResult> LoginUser(string userName, string Email)
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.NameIdentifier, userName),
new Claim(ClaimTypes.Email, Email),
new Claim("UserDefined", "whatever"),
};
var claimsIdentity = new ClaimsIdentity(claims, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用gRPC-Web制作Uno Platform的示例。
因此我从这篇文章提供的内容中得到了启发。我按照文章的说明创建了一个BlazorApp,它使用gRPC-Web 的天气服务。之后,我还添加了另一个服务,即计数器服务,如gRPC-Web 示例中所示。
一切正常后,我添加了一个Uno Platform WebAssembly应用程序来替换BlazorApp客户端。
当尝试创建应用程序时,GrpcChannel应用程序会获得一个System.NullReferenceException.
创建通道的代码片段如下所示:
var baseUri = "https://localhost:44366";
var channel = GrpcChannel.ForAddress(baseUri, new GrpcChannelOptions());
Run Code Online (Sandbox Code Playgroud)
这与BlazorApp中使用的代码完全相同。
BlazorApp和Uno Platform WebAssembly的示例代码可以在此存储库中找到。
任何想法/建议/帮助将不胜感激。
我正在尝试为主菜单中的按钮制作一个组件。
<NavLink href="@Href" title="@Title">
<div class="main-menu-button">
<img src="@IconUrl" />
<div class="label">
@Label
</div>
</div>
</NavLink>
@code {
[Parameter]
[EditorRequired]
public string? Href { get; set; }
[Parameter]
[EditorRequired]
public string? Label { get; set; }
[Parameter]
public string? Title { get; set; }
[Parameter]
[EditorRequired]
public string? IconUrl { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法在 css 文件中定位 NavLink。我已经尝试了所有这些不同的变体,但按钮在激活时永远不会改变颜色。
::deep a.active {
background-color: red !important;
}
::deep .active {
background-color: green !important;
}
::deep a .active {
background-color: blue !important;
}
a.active …Run Code Online (Sandbox Code Playgroud) 我需要构建一个 ASP.NET Core 托管的 Blazor Web assembly 应用程序 (.NET 6),其中所有应用程序功能都隐藏在登录墙后面,但我不确定如何最好地实现这一点。对于身份验证/授权,我使用 ASP.NET Identity 和 IdentityServer。
到目前为止,我已经创建了一个名为的新 Razor 组件Login.razor,它仅包含一个触发内置身份验证过程的链接:
<a href="authentication/login">Log in</a>
Run Code Online (Sandbox Code Playgroud)
该组件具有该@page指令"/",因此它是用户访问应用程序时登陆的第一个“页面”。
这工作得很好,但是一旦用户成功登录,他们就会被重定向到返回 URL,作为 .NET 身份过程的一部分,在本例中,这是一个现在无用的登录页面。
我不想只替换身份页面中的返回 URL 并将用户重定向到另一个特定页面,因为我认为返回 URL 在向用户发送指向特定页面的链接的情况下非常有用。例如,如果我尝试在不先登录的情况下导航到 mywebsite.com/fetchdata 等受保护资源,它会触发 Blazor 附带的任何身份验证魔法,让用户登录,然后在用户登录后将其重定向到 /fetchdata成功地做到了。我想保留这个功能。
"/index"如果用户来自 Login.razor 组件,我需要做什么才能让服务器重定向到另一个页面(例如)?或者我只是以完全错误的方式处理这一切?非常感谢任何建议。
asp.net-identity asp.net-core blazor blazor-webassembly hosted-blazor-webassembly
Index.razor.cs:
我正在开发一个网格组件,它将显示一个项目列表:
<Grid Items="Transactions">
<GridHeader>
<GridColumn TItem="Transaction">ID</GridColumn>
<GridColumn TItem="Transaction">Date</GridColumn>
</GridHeader>
</Grid>
Run Code Online (Sandbox Code Playgroud)
然后在 Grid.razor.cs 和 GridColumn.razor.cs 中我使用 typeparam TItem。但似乎我需要将 TITem 作为每个网格列中的参数传递,我该如何实现对类似以下内容的支持:
<Grid Items="Transactions" TItem="Transaction">
<GridHeader>
<GridColumn>ID</GridColumn>
<GridColumn>Date</GridColumn>
</GridHeader>
</Grid>
Run Code Online (Sandbox Code Playgroud)
因此,TItem 会级联到所有子组件(无论它们嵌套的深度如何)
我查看了 CascadingTypeParam 但有关它的信息很少,所以我不确定如果它是上述解决方案,如何使用它。
我正在开发一个针对 Blazor wasm 的类库,为了正常工作,客户端需要在其 Visual Studio 实例上安装 wasm-tools 工作负载。
有什么方法可以检查他们是否安装了它,如果没有安装,则生成某种错误消息?
谢谢。
我正在关注本教程https://dotnet.microsoft.com/en-us/learn/aspnet/blazor-tutorial/run,它构建了一个非常基本的 Blazor 应用程序。但是该项目无法在 ASP.NET Core 8 上运行。您能否帮忙找出为什么<app>runtimeconfig.json在构建 Blazor 项目时没有生成该文件?这是必需的,因为否则该项目将无法运行。该项目已成功构建,但我无法运行它。
我得到的错误是:
WasmAppHost --use-staticwebassets --runtime-config runtimeconfig.json
错误:无法在 /bin/Debug/net8.0/ 找到运行时配置
我尝试GenerateRuntimeConfigDevFile在文件中将属性设置为 true,.csproj如下所述: https: //learn.microsoft.com/en-us/dotnet/core/runtime-config/
但仍然没有创建 json 文件。
我尝试使用此处找到的模式手动创建它: https: //gist.github.com/natemcmaster/0bdee16450f8ec1823f2c11af880ceeb,但我收到有关缺少 WasmHostProperties 的错误。wasm 应用程序必须有一些特定的东西。
我想出了这个:
{
"runtimeOptions": {
"tfm": "net8.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "8.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Reflection.NullabilityInfoContext.IsSupported": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
},
"wasmHostProperties": {
"webServerPort":"7238",
"perHostConfig": [
{
"name": "wasmAppHost",
"host-args": [
"--experimental-wasm-simd", …Run Code Online (Sandbox Code Playgroud) blazor ×6
c# ×5
.net-8.0 ×1
asp.net-core ×1
async-await ×1
azure ×1
grpc-web ×1
msbuild ×1
uno-platform ×1
webassembly ×1