Blazor WASM 错误:“window.crypto.randomUUID 不是函数”

Pet*_*ris 3 azure-ad-msal blazor msal.js

当我部署 asp.net Blazor WASM 应用程序时,当 MSAL 尝试进行身份验证时,我收到以下错误。

window.crypto.randomUUID is not a function

我在微软的网站上看到过这篇文章,不确定它是否相关,但如果它被删除,我不会期望微软会在.NET 7中使用它。

我不知道该怎么办,有人可以帮忙吗?

到目前为止我尝试过的

  1. 将其放入我的客户端 csproj 文件中
<ItemGroup>
  <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
  1. 将其放入我的客户端 csproj 文件中
<ItemGroup>
  <BlazorLinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

在 xml 文件中添加此内容

<?xml version="1.0" encoding="utf-8" ?>
<linker>
  <assembly fullname="Microsoft.Authentication.WebAssembly.Msal" />
</linker>
Run Code Online (Sandbox Code Playgroud)

Pet*_*ris 6

问题是 window.crypto.randomUUID 仅在您的域是 localhost 或通过 HTTPS 请求时运行。

解决方案:使用https代替http(发布后似乎是VS默认的)。