【问题标题】:How to change base url?如何更改基本网址?
【发布时间】:2021-03-03 13:10:32
【问题描述】:

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

我们在一台机器上托管多个 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,其中后缀是配置值。

我使用这个blogpost 为控制器和页面的所有路由添加全局前缀,但现在我在处理静态文件时遇到了困难。

我可以虚拟移动wwwroot

app.UseStaticFiles(new StaticFileOptions
{
    RequestPath = $"/{GlobalPrefix}"
});

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

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

附: RTFM =)

【问题讨论】:

标签: asp.net-core


【解决方案1】:

在这种情况下使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    相关资源
    最近更新 更多