blazor.server.js 找不到并返回 ERR::ABORTED,如何解决?

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

我在 Startup.cs 中的所有设置正确时遇到了这个错误(有点)。并且_Host.cshtml也正常。我已经阅读了 blazor.server.js 404 not found 的段落,并尝试做同样的事情,但对我不起作用。

但可能影响我的项目的是,我用@page“/{*param}”捕获了Index.razor上的所有路由器。但不太可能,因为 _content/mudblazor.min.js 仍然可以访问。我问过 New bing,它回复了我无用的东西,并且不能应用在我的代码中。

更重要的是,我看到浏览器尝试获取 blazor.server.js,它确实只得到了 55B 的东西,这应该没什么用处。

我尝试了blazor.server.js 404 not found中的方法,还尝试修改UseEndpoints和MapFallbackToPage(由new bing建议)...

这些根本不起作用。

顺便说一句,我尝试使用代码禁止一些请求:

app.UseStaticFiles(new StaticFileOptions()
{

    OnPrepareResponse = s =>
    {
        s.Context.Response.Headers.Append("Cache-Control", $"public, max-age={(60 * 60 * 24 * 7).ToString()}");
        if (s.Context.Request.Path.StartsWithSegments(new PathString("/Sharlog")))
        {
            Console.WriteLine("BLOCK CRIT. ACCESS");
            s.Context.Response.StatusCode = 418;
            s.Context.Response.Body = Stream.Null;
            s.Context.Response.ContentLength = 0;
        }
    }
});

(呃,如何向此代码块澄清这是 C#?)

--- 更新:添加详细的我的_Host.cshtml:

@page "/"
@using Microsoft.AspNetCore.Components.Web
@using Shared
@namespace Sharlog.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="~/" />
    @* <script src="_framework/blazor.server.js"></script> *@
    <environment include="Staging, Development">
        <script src="https://cdn.tailwindcss.com"></script>
    </environment>
    <environment include="Production">
        <link />
        @*universal Tailwind CSS*@
    </environment>
    @*<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />*@
    <link href="css/site.css" rel="stylesheet" />
    <link href="Sharlog.styles.css" rel="stylesheet" />
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
    <link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
    <link rel="icon" type="image/png" href="favicon.png" />
    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />


</head>
<body>
    <component type="typeof(App)" render-mode="ServerPrerendered" />
@* @Body render start here ^ *@

    <div id="blazor-error-ui">
        <BlazorErrUI />
        <environment include="Staging,Production">
            An error has occurred. This application may no longer respond until reloaded.
        </environment>
        <environment include="Development">
            An unhandled exception has occurred. See browser dev tools for details.
        </environment>
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>

    <script src="_framework/blazor.server.js"></script>
    <script src="_content/MudBlazor/MudBlazor.min.js"></script>
</body>
</html>

c# blazor signalr blazor-server-side
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.