We have a series of smaller APIs part of a larger system, each running in their own sites on an IIS machine.
To hide our internal architecture, we've created a series of IIS rewrite rules:
<rule name="AuthServer" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^auth/.*" />
<action type="Rewrite" url="https://localhost:4000/{R:0}" />
</rule>
However, we need to extend this system and make it testable.
We've tried:
if (context.Request.Uri.AbsoluteUri.EndsWith("test"))
{
context.Request.Path = new PathString("/rewritten");
}
But this only allows us to change the path. We need to rewrite to a different port/site.
Can this be done?
We didn't find a way to do this, so we ended up using:
To dynamically update the web.config rewrite rules from code. It works fine, and is testable (though not locally hosted).