HttpContext.Current.Request.Url.Authority in NLB

B

Billy Zhang

I have a NLB environment. 102 and 103 are the two machines' IP.
107 is the virtual IP. I used below code to get the URI.

public static string GetEnvironment()
{
return "http://" +
HttpContext.Current.Request.Url.Authority +
HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";
}

The problem is that:

sometimes I got 107, and sometimes I got 102. Why?
 
S

Steven Cheng

Hi Billy,

It seems the behavior you watched is likely the expected behavior. The
following thread was focus on the same issue:

NLB, IIS 6.0, .NET ASP Web App Randomly Changing URL From Hostname
http://bytes.com/groups/net/122411-nlb-iis-6-0-net-asp-web-app-randomly-chan
ging-url-hostname

As Nick Malik explained in it, within a NLB environment, the "Request.Url"
contains the url the NLB virtual server(proxy server) used to access the
backend physical server. And this is not reliable for using in your ASP.NET
page's code(to emit some links' url).

If you want to expose some absolute link, for ASP.NET page, here are some
recommended means:

1. As mentioned in the above article, you can use the front NLB virtual
address (FQDN name) instead of IP.
2. You can use "~/..." like url in your server control .e.g.

<asp:Image ImageUrl="~/images/xxxx.jpg" />

"~/..." means start from the application's root directory and will be
parsed by ASP.NET runtime correctly. If you want to use it in client-side
html markup, you can use code like this:

<img src='<%= ResolveUrl("~/images/xxx.jpg"") %>' />


Or you can use relative url so as to avoid include host name part.

If there is any further questions, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top