非启动程序集中的 ASP.NET Core 8.0 MapRazorPages

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

我正在编写一个 ASP.NET Core 8.0 网站,我想为人们提供 2 种不同的选择。查看云中的站点(托管在共享 IIS 中)或运行在本地无线网络上托管同一服务器的 WPF 桌面应用程序。

在一个程序集中,我有一个 .NET 8.0 最小风格的剃刀页面网站。当我从 Visual Studio 运行该网站时,它可以工作。

我有一个 WPF 应用程序,它依赖于网站程序集的项目。当我从 WPF 应用程序运行同一网站时,路由表中没有出现任何 Razor 页面,并且所有内容都出现 404 错误。在我看来,

app.MapRazorPages
没有搜索除启动程序集之外的任何程序集。

有没有一种简单的方法来告诉

MapRazorPages
查看不同的程序集?

我运行以下代码来启动自托管网络服务器。

public static async Task RunWebsite(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);
    builder.Host.UseServiceProviderFactory(
        new MelvilleServiceProviderFactory(true, i => new RegisterIocServices(i).Register()));
    builder.WebHost.UseUrls("http://*:7000");

    new ConfigAspNetServices(builder).Config();

    var app = builder.Build();

    await new HttpRequestPipeline(app).Configure(false);

    await app.RunAsync();
}

配置HTTP管道的代码在网站和本地网站之间共享

public readonly partial struct HttpRequestPipeline
{
    [FromConstructor] private readonly WebApplication app;

    public async ValueTask Configure(bool httpsOnly)
    {
        await using (var scope = app.Services.CreateAsyncScope())
        {
            await scope.ServiceProvider.GetRequiredService<InitalizationExecutor>().DoInitalize();
        }

        if (httpsOnly) RequireHttps();
        
        #if DEBUG
        app.UseRouteDebugger();
        #endif

        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.MapRazorPages();
    }

    private void RequireHttps()
    {
        app.UseHttpsRedirection();
        // Configure the HTTP request pipeline.
        if (app.Environment.IsDevelopment())
        {
            app.UseMigrationsEndPoint();
        }
        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();
        }
    }
}
asp.net-core razor-pages asp.net-core-8
1个回答
0
投票

有没有一种简单的方法可以告诉 MapRazorPages 以不同的方式查看 组装?

致电

builder.Services.AddRazorPages().AddApplicationPart({targetassembly});

您可以查看此文档了解更多详情

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