Question

I have 3 websites that run from a load-balanced pool of servers. Load-balancer uses sticky sessions to ensure that session stays on initial pool.

In the website, I need to generate a url specific to the website. As per standard procedure I tried to use HttpContext.Request.Url, but this returns the wrong url. I then tried to use Request.ServerVariables["HTTP_HOST"] and that returns the correct url.

Does anyone have any ideas?

On Site A: Request.Url returns Url A Request.ServerVariables["HTTP_HOST"] returns Url A

On Site B:

Request.Url returns Url A Request.ServerVariables["HTTP_HOST"] returns Url B

On Site C:

Request.Url returns Url A Request.ServerVariables["HTTP_HOST"] returns Url C

Was it helpful?

Solution

Request.ServerVariables["HTTP_HOST"] return IIS host, i.e. the host name your website is set to respond to. That may or may not be the same host as in URL client executed to get to your page. The behavior you see is totally logical since client always executes the same URL, but the load balancer send it to different IIS instances.

edit: on that note I am confused as to why would you need to have "a url specific to the website"?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top