如何更改基本网址?

Pav*_*nin 4 asp.net-core

我不确定问题的标题是否正确,但我会尽力解释我需要什么。

我们在一台机器上托管多个 Web 应用程序,因此

https://localhost:8080

https://localhost:8081

指向不同的应用。

同时,API网关在不删除URL后缀的情况下映射请求:

https://api.domain.com/service1/Home/Index

变成

https://localhost:8080/service1/Home/Index

https://api.domain.com/service2/Home/Index

进入

https://localhost:8081/service2/Home/Index

我希望应用程序的根~解析为hostUrl+suffix后缀是配置值。

我使用这篇博文为控制器和页面的所有路由全局添加前缀,但现在我在处理静态文件。

我几乎可以移动wwwroot

app.UseStaticFiles(new StaticFileOptions
{
    RequestPath = $"/{GlobalPrefix}"
});
Run Code Online (Sandbox Code Playgroud)

但渲染时<link href="~/bootstrap/css/bootstrap.css" rel="stylesheet" />不包含部分。GlobalPrefix

所以我想将其添加GlobalPrefix到托管的任何基本 URL 站点中。无论是自托管应用程序还是 IIS 中的应用程序。

PS RTFM =)

Dab*_*oul 8

在这种情况下,使用app.UsePathBase("/myPath")https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-2.2)是有效的。

ASP.NET Core 2 对此进行了更改 ( http://github.com/aspnet/Announcements/issues/226 )。另外,请注意一个奇怪的行为:http://github.com/aspnet/HttpAbstractions/issues/893