IIS 7 and Above
UserHostName / REMOTE_ADDR Empty on IIS
Last post Feb 08, 2008 05:54 PM by anilr
Feb 04, 2008 02:30 PM|mkellerm|LINK
I have an ASP.NET 2.0 Application that I am beginging to test on IIS 7.0.
The problem is that when ever I attemt to get the Request.UserHostName or Request.Params["REMOTE_ADDR"] I always get a response of - - 1 instead of the actual host name or IP Address. This is only occuring on IIS 7. I am using 2008 Server RC1 64 bit Enterprise
I can reproduce it with a simple test page as well.
protected void Page_Load(object sender, EventArgs e)
Page.Response.Write(Request.UserHostName + "<br>");
Page.Response.Write(Request.UserHostAddress + "<br>");
Page.Response.Write(Request.UserAgent + "<br>");
Feb 04, 2008 06:02 PM|anilr|LINK
REMOTE_ADDR contains the ip address (not the host name) - so if you make request to localhost, ::1 is the ip address. To get the host name, you need to turn on reverse dns lookup system.webServer/security/ipSecurity@doReverseDns and get the REMOTE_HOST
Feb 08, 2008 02:30 PM|mkellerm|LINK
Interesting... That is a change in behavior between IIS 6 and IIS 7 In IIS 6 I would get the loopback adapter IP address 127.0.0.1 instead of ::1
I don't know why I didn't think to test this with the actual machine name instead, I guess the ::1 threw me off. No I see the address as
fe80::f07d:bf82:a142:7e81%10 I am not familar with that format. How do I convert it to an IP Is it a byte array that is : delimited?
Feb 08, 2008 05:54 PM|anilr|LINK
That is an ipv6 address - ipv6 is enabled and default in vista/ws08.