How to get the URL of the application database behind the reverse proxy server

Is there a way that an ASP.NET application can display its URLs and hostname, knowing its own routes in the context of a request passing through a reverse proxy?

When requesting this URL through the gateway:

http://conoso.com/behind/some/reverseproxy/api/values/

The request is redirected by the gateway to another location:

http://10.0.0.0/api/values

It accesses the following Get ValuesController Get ApiController method using the DefaultApi route:

// GET api/values
public HttpResponseMessage Get()
{
  var res = Request.CreateResponse();
  res.Headers.Add(
    "Location",
    Url.Link(
      "DefaultApi",
      new
        {
          id = 1
        }));
  return res;
}

It returns the following header value:

Location: http://10.0.0.0/api/values/1

while I was hoping to send the correct path:

Location: http://conoso.com/behind/some/reverseproxy/api/values/1

An alternative to using inline methods in a structure is to manually format the string:

var baseUrl = "http://conoso.com/behind/some/reverseproxy";
string.Format("{0}/values/1", baseUrl);

But this eliminates the evil code. Is there a cleaner approach?

+4
1

. REST URL- , java script. , .

, , ( ):

<a id="urlBase" href="/" style="display: none;"></a>
<script type="text/javascript">
    baseUrl = document.getElementById('urlBase').getAttribute('href');
</script>

href="/" href="/path/", baseUrl REST.

, .

( , , , )

0

All Articles