【问题标题】:How to URL rewrite to another domain in .NET Core?如何将 URL 重写到 .NET Core 中的另一个域?
【发布时间】:2020-03-26 12:32:24
【问题描述】:

我有一个在 PaaS 中托管的带有 .NET Core 后端的 React 应用程序。我正在尝试 URL 将请求重写到另一个应用程序,但我无法将其重写到另一个域。例如:

我的应用程序位于:

https://example.com

我的 JS 向 /api/orders 发出 GET 请求,然后我有一个请求:

https://example.com/api/orders

我正在尝试使用 URL Rewrite 中间件将此请求重写为:

https://another-example.com/api/orders

我已经尝试过使用这个:

RewriteOptions rewriteOptions = new RewriteOptions()
    .AddRewrite(@"^api/orders/(.+)", "https://another-example/api/orders/$1", skipRemainingRules: true);

还创建了一个实现IRule 接口的类,但没有一个工作。这些仅适用于相同的域重写。有没有办法做到这一点?

【问题讨论】:

标签: c# asp.net-core url-rewriting


【解决方案1】:

随 ASP.NET Core 2.x 发布的中间件不支持出站规则

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-3.0

【讨论】:

    猜你喜欢
    • 2019-07-02
    • 2021-10-22
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    相关资源
    最近更新 更多