Owin URL 重写到不同的端口

Owin URL Rewrite to different port

我们有一系列较小的 API 组成了一个较大的系统,每个 运行 在 IIS 机器上各自的站点中。

为了隐藏我们的内部架构,我们创建了一系列 IIS 重写规则:

<rule name="AuthServer" patternSyntax="ECMAScript" stopProcessing="true">
    <match url="^auth/.*" />
    <action type="Rewrite" url="https://localhost:4000/{R:0}" />
</rule>

但是,我们需要扩展这个系统并使其可测试。

我们已经尝试过:

if (context.Request.Uri.AbsoluteUri.EndsWith("test"))
{
    context.Request.Path = new PathString("/rewritten");
}

但这只能让我们改变路径。我们需要重写为不同的 port/site.

这可以做到吗?

我们没有找到这样做的方法,所以我们最终使用了:

https://msdn.microsoft.com/en-us/library/microsoft.web.administration.servermanager.getwebconfiguration(v=vs.90).aspx

从代码中动态更新 web.config 重写规则。它工作正常,并且可以测试(虽然不是本地托管的)。