Blazor WebAssembly 应用程序由于完整性错误而无法加载

问题描述 投票:0回答:6

我们开发了一个 Blazor WebAssembly 应用程序,该应用程序已经为特定客户群投入生产使用。

该应用程序适用于所有具有标准安全设置的浏览器。然而,今天早上我接到了一位客户的电话,他们的 Chrome 浏览器中根本没有加载应用程序。

我在控制台看到以下错误:

  • Unknown error occurred while trying to verify integrity.
  • Failed to load resource: the server responded with a status of 403 (forbidden)
  • Failed to find a valid digest in the 'integrity' attribute for ressource '<somepath.dll>' with SHA-256 integrity <sha56>. the resource has been blocked

现在我的问题是,是什么原因造成的?这是浏览器安全设置,还是其他安全设置,例如在服务器上、在代码中等?我该如何解决这个问题?

这是上面提到的错误的图片

security browser blazor
6个回答
4
投票

发生这种情况的最可能原因是某些防病毒软件阻止执行下载的

.dll
文件。这就是为什么它在某些网络中有效,但在其他一些网络中无效的原因。

您可以做的,以及 被微软 推荐为解决方法的方法,是将所有

.dll
重命名为
.bin
- 并更改配置 json。它适用于我的情况。

我为此使用以下 PowerShell 函数:

Function Hide-BlazorDLL {

    Param(
        [string]$Path = (Get-Location).Path
    )

    <#
        According to the following Links:
        https://github.com/dotnet/aspnetcore/issues/19552
        https://github.com/dotnet/aspnetcore/issues/5477#issuecomment-599148931
        https://github.com/dotnet/aspnetcore/issues/21489
        https://gist.github.com/Swimburger/774ca2b63bad4a16eb2fa23b47297e71 
    #>

    # Test if path is correct and accessible
    $WorkingDir = Join-Path $Path "_framework"
    if (!(Test-Path $WorkingDir)) { Throw "Wrong path $Path. current location must be wwwroot folder of published application." }

    # Get All Items
    $AllItems = Get-ChildItem $WorkingDir -Recurse
    $DLLs = $AllItems | Where-Object { $_.Name -like '*.dll*' }
    $BINs = $AllItems | Where-Object { $_.Name -like '*.bin*' }

    # End script if no .dll are found
    if ($DLLs) { 

        # Delete all current .bin files
        if ($BINs) {
            Remove-item $BINs.FullName -Force
        }
    
        # Change .dll to .bin on files and config
        $DLLs | Rename-item -NewName { $_.Name -replace ".dll\b",".bin" }
        ((Get-Content "$WorkingDir\blazor.boot.json" -Raw) -replace '.dll"','.bin"') | Set-Content "$WorkingDir\blazor.boot.json"
    
        # Delete Compressed Blazor files
        if (Test-Path "$WorkingDir\blazor.boot.json.gz") {
            Remove-Item "$WorkingDir\blazor.boot.json.gz"
        }
        if (Test-Path "$WorkingDir\blazor.boot.json.br") {
            Remove-Item "$WorkingDir\blazor.boot.json.br"
        }
    
        # Do the same for ServiceWorker, if it exists
        $ServiceWorker = Get-Item "$Path\service-worker-assets.js" -ErrorAction SilentlyContinue
        if ($ServiceWorker) {
            ((Get-Content $ServiceWorker.FullName -Raw) -replace '.dll"','.bin"') | Set-Content $ServiceWorker.FullName
            Remove-Item ($ServiceWorker.FullName + ".gz")
            Remove-Item ($ServiceWorker.FullName + ".br")
        }
    }
    else {
        Write-Host "There are no .dll Files to rename to .bin" 
    }
}

基本上,您需要导航到已发布应用程序的

wwwroot
文件夹并在那里运行该功能。例如:

PS D:\inetpub\wwwroot\<appname>\wwwroot> Hide-BlazorDLL

2
投票

我的解决方案是删除客户端和服务器项目文件夹中的

obj
bin
文件夹


1
投票

当我在匿名浏览器窗口(谷歌浏览器)中测试我的应用程序时,由于某种原因这个错误不断发生。

如果遇到完整性错误,请尝试使用普通浏览器窗口。

此外,如果您使用的是 Cloudflare CDN,请不要忘记在缓存中“清除所有内容”。


1
投票

我们在使用 Cloudflare 自动缩小功能时遇到过这个问题。该功能会删除 html、js 和其他文件中的任何注释——某些 blazor .js 文件似乎包含这些文件。

这意味着文件内容的哈希值不再与在 blazor.boot.json 中找到的哈希值相匹配 -> 将抛出完整性问题并停止应用程序加载。

禁用自动缩小功能解决了这个问题。


0
投票

技术栈:

.NET 6.0.11

我有一个类似的问题。在本地机器上,它工作正常。但是当它通过 GitHub Actions 部署时,我收到完整性检查错误。我在 Blazor WebAssembly ASP.NET Core 托管 (WebAssemblyPrerendered) 项目中遇到了这个问题。这是我遵循的修复方法。

  1. .gitattributes
    文件添加到解决方案根文件夹中。
  2. 在文件末尾添加以下代码。
# blazor dlls - treat all .dll files as binary
*.dll binary

0
投票

对我来说,这只是不小心删除了对

IApplicationBuilder.UseBlazorFrameworkFiles()
的调用。我建议仔细检查您的代码以确定。

© www.soinside.com 2019 - 2024. All rights reserved.