Asp.net core ASPNET Core 3.1 Razor页面,在kestrel中具有虚拟目录
我有两个网站使用AspnetCore3.1RazorPages开发,由kestrel托管。例如:Asp.net core ASPNET Core 3.1 Razor页面,在kestrel中具有虚拟目录,asp.net-core,kestrel-http-server,Asp.net Core,Kestrel Http Server,我有两个网站使用AspnetCore3.1RazorPages开发,由kestrel托管。例如: https://localhost:50001/* https://localhost:50002/* https://example.com/MyAppA/* https://example.com/MyAppB/* 在调试模式下运行时没有问题。然而,在生产中,我想使用旧的IIS方法,我们可以在URL中添加一个虚拟目录。例如: https://localhost:50001/* https:/
https://localhost:50001/*
https://localhost:50002/*
https://example.com/MyAppA/*
https://example.com/MyAppB/*
在调试模式下运行时没有问题。然而,在生产中,我想使用旧的IIS方法,我们可以在URL中添加一个虚拟目录。例如:
https://localhost:50001/*
https://localhost:50002/*
https://example.com/MyAppA/*
https://example.com/MyAppB/*
我知道kestrel无法做到这一点,但我也不能使用IIS,因为我需要在非windows环境中部署这些网站
我是否可以修改Razor页面中的路由以在我的代码中添加MyAppA或MyAppB
最简单的方法是将[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
中间件,请在此处尝试答案这些网站在不同的ASP.NET项目中吗?如果是这样,在将请求转发到服务之前,您可能需要一个反向代理来处理请求。这只是将默认根目录更改为MyAppA(意味着在此设置之前必须存在MyAppA),而不是将MyAppA附加到URL中谢谢!这正是我需要的