Monday, June 09, 2008

Getting Client IP address using ASP.NET C#

You can use the following three ways to get the client IP address using C#

string test = Request.UserHostAddress.ToString();
string test2 = Request.ServerVariables["REMOTE_ADDR"].ToString();
string test3 = Context.Request.UserHostAddress.ToString();

All are returning the same values...

Some times client can mask their IP behind a router/nat and it's spoofable.


No comments: