RequestUri in HttpRequestMessage does not keep original host

Topics: Web Api
Feb 17, 2011 at 1:37 PM

Hi,

I am trying to implement a RESTful service that uses the host from the Request Uri to determine the tenant making the request.

For example, if a client sends a request to http://tenant1.mycompany.com, I would like to be able to retrieve the "tenant1" value.

However, when I use the code below I'm seeing that the original Uri was lost, and the host name is being replaced with the machine name.

Is this the right way to find the original Uri? Am I running into a bug?

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public void Post(HttpRequestMessage request, HttpResponseMessage response)
        {
            var requestUri = request.RequestUri;
        }

Thanks,

Mario

Feb 17, 2011 at 6:55 PM

Hi Mario, I'm not sure this is going to work, but you can try defining your method like this:

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public void Post(HttpRequestMessage request, HttpResponseMessage response, Uri Uri)
        {
            var requestUri = Uri;
        }


Let me know if that works!
Gustavo
Feb 17, 2011 at 10:20 PM

No luck unfortunately... I get the same Uri value...

Mario