Blazor 服务器应用程序在部署时无法运行,在 Visual Studio 中运行良好

Blazor server app not working when deployed, works fine in Visual Studio

我有一个 Blazor 服务器端项目,我一直在 Visual Studio 2019 年使用 .NET5 开发该项目。一切正常。

我刚刚将该站点部署到测试服务器(其中已经 运行 部署了两个这样的站点,所以我知道该服务器拥有 运行 该站点所需的一切) ,但 none 的 Blazor 东西似乎有效。具体...

不知道要显示什么代码,因为在 VS 中 运行ning 时一切正常。这是 App.razor...

的内容
<CascadingAuthenticationState>
  <Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
      <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
        <NotAuthorized>
          <RedirectToLogin />
        </NotAuthorized>
      </AuthorizeRouteView>
    </Found>
    <NotFound>
      <AuthorizeView>
        <Authorized>
          <LayoutView Layout="@typeof(MainLayout)">
            <NotFound />
          </LayoutView>
        </Authorized>
        <NotAuthorized>
          <RedirectToLogin />
        </NotAuthorized>
      </AuthorizeView>
    </NotFound>
  </Router>
</CascadingAuthenticationState>

_Imports.razor 文件包含所有正确的 using,具体包括...

@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web

非登录用户不应访问的页面在代码隐藏中用 [Authorize(Roles = "Admin")] 修饰,或在 .razor 文件中用 @attribute [Authorize(Roles = "Admin")] 修饰。

有人知道我做错了什么吗?如果我能提供更多信息,请告知。谢谢

更新 我刚刚尝试将网站部署到同一台服务器上的另一个域,运行没问题。我还尝试将另一个站点指向这个站点的文件夹,它工作正常(所以它不是部署的文件),然后将这个站点指向另一个文件夹,但它没有用。所以,看起来网站本身有问题,但我不知道它看起来像其他什么。

原来问题与我的代码无关,也与我在服务器上的站点设置无关。我使用 Cloudflare,并将其设置为缩小 HTML。这将删除 Blazor 工作所必需的两个 HTML 注释。有关详细信息,请参阅 this article

因此,如果您使用的是 Cloudflare,请务必将其设置为缩小 JavaScript 和 CSS,但不要缩小 HTML.