【问题标题】:Blazor Webassembly Azure AD Authentication in .net 6.0 exception invalid Url.net 6.0 异常中的 Blazor Webassembly Azure AD 身份验证 URL 无效
【发布时间】:2022-02-02 20:45:35
【问题描述】:

我将我的客户项目升级到 .net 6.0, 在 IIS 中部署后出现属性未定义错误, 我将 TrimmerRootAssembly 添加到 csproj


    <ItemGroup>
        <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
      </ItemGroup>

作为这个问题的建议 Blazor WASM Net 6 Preview 4 Azure AD - There was an error trying to log you in: 'Cannot read property 'toLowerCase' of undefined' 但后来我得到另一个错误无效的 URL

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
  Unhandled exception rendering component: Failed to construct 'URL': Invalid URL
  TypeError: Failed to construct 'URL': Invalid URL
      at new u (https://devdms/_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js:2:191011)
      at Function.init (https://devdms/_content/Microsoft.Authentication.WebAssembly.Msal/AuthenticationService.js:2:196273)
      at https://devdms/_framework/blazor.webassembly.js:1:3332
      at new Promise (<anonymous>)
      at Object.beginInvokeJSFromDotNet (https://devdms/_framework/blazor.webassembly.js:1:3306)
      at Object.Rt [as invokeJSFromDotNet] (https://devdms/_framework/blazor.webassembly.js:1:59738)
      at _mono_wasm_invoke_js_blazor (https://devdms/_framework/dotnet.6.0.1.716ng6fo9h.js:1:194546)
      at https://devdms/_framework/dotnet.wasm:wasm-function[219]:0x1a129
      at https://devdms/_framework/dotnet.wasm:wasm-function[167]:0xcaf7
      at https://devdms/_framework/dotnet.wasm:wasm-function[166]:0xba0a

Microsoft.JSInterop.JSException:无法构造“URL”:无效的 URL TypeError:无法构造“URL”:无效的 URL

知道问题是什么吗?顺便说一句,该项目在本地工作没有任何问题

【问题讨论】:

    标签: azure-active-directory blazor-webassembly .net-6.0


    【解决方案1】:

    请检查web中形成的地址,哪里出错,修改代码中的认证请求。

    打开 appsettings.json 文件并检查权限、回调路径等所有值是否配置正确或实例、域...是否正确提供。

    "AzureAd": {
        "Instance": "https://login.microsoftonline.com/",
        "Domain": " ",
        "TenantId": " ",
        "ClientId": " ",
        "CallbackPath": "/signin-oidc"
      },
    

    并确保在身份验证刀片 Ex:https://localhost:1443/signin-oidc 下的 azure 应用注册中提供了有效的重定向 url。 如果添加了任何范围,请务必同意权限。

    删除 bin & obj 文件夹,清除浏览器缓存。删除服务器上目标文件夹中的所有文件,然后在发布之前重建解决方案。

    chrome 扩展也可能有问题。

    参考:Blazor WASM Net 6 Preview 4 Azure AD (github.com)

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      • 2022-08-16
      • 2020-11-06
      • 2020-11-02
      • 2020-09-16
      • 2021-07-22
      相关资源
      最近更新 更多