我不确定问题的标题是否正确,但我会尽力解释我需要什么。
我们在一台机器上托管多个 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}"
});
但在渲染时<link href="~/bootstrap/css/bootstrap.css" rel="stylesheet" />
不包含GlobalPrefix
部分。
所以我想将此添加GlobalPrefix
到托管的任何基本 URL 站点。无论是自托管应用程序还是在 IIS 中。
PS RTFM =)
在这种情况下,使用app.UsePathBase("/myPath")
(https://docs.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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句