Wednesday, November 21, 2012

asp.net , Request.Url differs between .net versions with Load balancer

Got a weird problem, here is the quick story. I have several Web servers with the web app binding to private port 8011. the Load balancer has a Name like LB. when the page display the request Uri. it returns very weird format.  http://LB:8081 (so basically, LB name + Private Port) , no body can access this Url.

To do the simple test. I setup one test page on IIS with port8011, return the current URL.
image

then try access using the private url, it’s ok

image

However, if I setup one LB with LB_NAME, and LISTEN on Port 8888. then I try access the LB address. get unreachable url.
image

then I check the code, for .net 4.0. it has the option to follow the Url  from the user request. add one setting called aspnet:UseHostHeaderForRequestUrl
image

then we get the url as user sent in the request
image

If you check the .net 4.0 code, it has the following logic to get URL.

image

code to get new settings,
image

 

But this only applies to .net fx with latest patch. so check the code using reflector in your real case.

No comments:

 
Locations of visitors to this page