带有 kestrel 中虚拟目录的 ASPNET Core 3.1 Razor Pages

ASPNET Core 3.1 Razor Pages with virtual directory in kestrel

我有两个使用 Aspnet core 3.1 Razor Pages 开发的网站,由 kestrel 托管。示例:

https://localhost:50001/*
https://localhost:50002/*

调试模式下运行没有问题。但是在生产中我想使用旧的 IIS 方法,我们可以将虚拟目录添加到 URL。示例:

https://example.com/MyAppA/*
https://example.com/MyAppB/*

我知道 kestrel 不能这样做,但我也不能使用 IIS,因为我需要在非 windows 环境中部署这些网站。

请问我是否可以修改 Razor Pages 中的路由以在我的代码中添加 MyAppAMyAppB

最简单的方法是将 [solution]\Pages\* 中的所有页面移动到 [solution]\Pages\MyAppA\*,但我会将此保留为最后一个选项。

谢谢

你可以试试这个,

public void ConfigureServices(IServiceCollection services)
{
      services.AddRazorPages(options =>
      {
           //this is page level so you need to add every page
           options.Conventions.AddPageRoute("/index", "MyAppA");
           options.Conventions.AddPageRoute("/test1", "MyAppA/test1");
      });
}

如何使用PathBase中间件,请尝试这里的答案