On the gateway server you can create a rule at the server or site level. Here's an example:
<rule name="Add Gateway Header">
<match url=".*" />
<set name="HTTP_ServiceGateway" value="1" />
<action type="None" />
Note that if you create this at the site level that you'll need to give permission for that server variable to be set at the site level. That's set in URL Rewrite at the server level under "View Server Variables", if you're using IIS Manager.
way to add this to an ASPX page is:
<%= Request.ServerVariables("HTTP_ServiceGateway") %>. Obviously you can do this from an MVC view or other framework.
Or you could call the variable HTTP_ServiceGatewayRootPath and include the root path. Then you can control the root path from the gateway rather than your code.