Override host of webapi odata links
<p>I'm using WebAPI 2.2 and Microsoft.AspNet.OData 5.7.0 to create an OData service that supports paging.</p>

<p>When hosted in the production environment, the WebAPI lives on a server that is not exposed externally, hence the various links returned in the OData response such as the <code>@odata.context</code> and <code>@odata.nextLink</code> point to the internal IP address e.g. <code>http://192.168.X.X/&lt;AccountName&gt;/api/...</code> etc.</p>

<p>I've been able to modify the <code>Request.ODataProperties().NextLink</code> by implementing some logic in each and every ODataController method to replace the internal URL with an external URL like <code>https://account-name.domain.com/api/...</code>, but this is very inconvenient and it only fixes the NextLinks.</p>

<p>Is there some way to set an external host name at configuration time of the OData service? I've seen a property <code>Request.ODataProperties().Path</code> and wonder if it's possible to set a base path at the <code>config.MapODataServiceRoute("odata", "odata", GetModel());</code> call, or in the <code>GetModel()</code> implementation using for instance the <code>ODataConventionModelBuilder</code>?</p>

<hr>

<p><strong>UPDATE:</strong> The best solution I've come up with so far, is to create a <code>BaseODataController</code> that overrides the <code>Initialize</code> method and checks whether the <code>Request.RequestUri.Host.StartsWith("beginning-of-known-internal-IP-address")</code> and then do a RequestUri rewrite like so:</p>

<pre><code>var externalAddress = ConfigClient.Get().ExternalAddress;  // e.g. https://account-name.domain.com
var account = ConfigClient.Get().Id;  // e.g. AccountName
var uriToReplace = new Uri(new Uri("http://" + Request.RequestUri.Host), account);
string originalUri = Request.RequestUri.AbsoluteUri;
Request.RequestUri = new Uri(Request.RequestUri.AbsoluteUri.Replace(uriToReplace.AbsoluteUri, externalAddress));
string newUri = Request.RequestUri.AbsoluteUri;
this.GetLogger().Info($"Request URI was rewritten from {originalUri} to {newUri}");
</code></pre>

<p></p>

<p>This perfectly fixes the <code>@odata.nextLink</code> URLs for all controllers, but for some reason the <code>@odata.context</code> URLs still get the <code>AccountName</code> part (e.g. <a href="https://account-name.domain.com/AccountName/api/odata/" rel="noreferrer">https://account-name.domain.com/AccountName/api/odata/</a>$metadata#ControllerName) so they still don't work.</p>