找不到Blazor WASM.Net5预渲染页

找不到Blazor WASM.Net5预渲染页,blazor,webassembly,.net-5,Blazor,Webassembly,.net 5,我已经建立了一个基本的WASM托管模板,并已转换为以下预渲染 及 一切似乎都如预期的那样工作,我可以点击导航链接,它会按预期更改页面。但是,我无法通过URL直接导航到页面。如果我输入localhost:port/Counter,我会得到一个找不到的localhost页面。当我单击计数器的导航链接时,它将URL显示为localhost:port/counter 为什么我不能直接导航到URL 编辑: 下面是一些文件,以了解发生了什么 这是Server Startup.cs public class

我已经建立了一个基本的WASM托管模板,并已转换为以下预渲染

一切似乎都如预期的那样工作,我可以点击导航链接,它会按预期更改页面。但是,我无法通过URL直接导航到页面。如果我输入localhost:port/Counter,我会得到一个找不到的localhost页面。当我单击计数器的导航链接时,它将URL显示为localhost:port/counter

为什么我不能直接导航到URL

编辑:

下面是一些文件,以了解发生了什么

这是Server Startup.cs

public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddControllersWithViews();
            services.AddRazorPages();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                //endpoints.MapFallbackToFile("index.html");
                endpoints.MapFallbackToFile("/_Host");
            });
        }
此处的更改是更改/u主机的mappfallbacktofile。这是添加到Server/Pages文件夹的新文件,如下所示

@page "/"
@using BlazorAppNet5WasmHosted.Client
@namespace BlazorAppNet5WasmHosted.Server.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
    <html>

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <title>BlazorAppNet5WasmHosted</title>
        <base href="/" />
        <link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
        <link href="css/app.css" rel="stylesheet" />
        <link href="BlazorAppNet5WasmHosted.Client.styles.css" rel="stylesheet" />
    </head>

    <body>
        <component type="typeof(App)" render-mode="WebAssemblyPrerendered" />
        <script src="_framework/blazor.webassembly.js"></script>
    </body>

</html>

在我启动的服务器中,将回退更改为/\u主机

app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                //endpoints.MapFallbackToFile("index.html");
                endpoints.MapFallbackToFile("/_Host");
            });

但是问题是它不应该是endpoint.MapFallbackToFile_Host;它应该是endpoints.MapFallbackToPage//u主机;这就是导致刷新失败的原因

在我启动的服务器中,该服务器将回退更改为/\u主机

app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                //endpoints.MapFallbackToFile("index.html");
                endpoints.MapFallbackToFile("/_Host");
            });

但是问题是它不应该是endpoint.MapFallbackToFile_Host;它应该是endpoints.MapFallbackToPage//u主机;这就是导致刷新失败的原因

共享您的代码实际上没有什么特别要共享的。它是开箱即用的.Net5 Blazor应用程序WebAssembly托管模型,已使用新的prerender进行了设置,如上述URL博客文章所述。没有一个特定的代码部分要显示,它实际上是整个项目,这取决于您如何设置它,因此有一些想法可以共享:_host.cshtml、Statup.cs和blazor app Program.cs随服务器启动而更新,而_hostfilesenet并没有真正回答我的问题。我已经将其设置为直接预呈现到URL的导航,这是失败的共享您的代码实际上没有什么特别要共享的。它是开箱即用的.Net5 Blazor应用程序WebAssembly托管模型,已使用新的prerender进行了设置,如上述URL博客文章所述。没有一个特定的代码部分要显示,它实际上是整个项目,这取决于您如何设置它,因此有一些想法可以共享:_host.cshtml、Statup.cs和blazor app Program.cs随服务器启动而更新,而_hostfilesenet并没有真正回答我的问题。我已经将其设置为预渲染,直接导航到失败的URL