Sasikumar S

Sasikumar S

  • NA
  • 29
  • 36.8k

Find visitor's location using IP address

Jul 28 2011 4:06 AM
Hi friends,

  I have some problem to finding visitor's location.my code could be produce some error. i have pasted my code below

Code:

string ipaddress;
System.Web.HttpRequest Request;
ipaddress =Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (ipaddress == "" || ipaddress == null)

ipaddress = Request.ServerVariables["REMOTE_ADDR"];



DataTable dt = GetLocation(ipaddress);

if (dt != null)
{

if (dt.Rows.Count > 0)
{

city = dt.Rows[0]["City"].ToString();

RegionName = dt.Rows[0]["RegionName"].ToString();

CountryName = dt.Rows[0]["CountryName"].ToString();

CountryCode = dt.Rows[0]["CountryCode"].ToString();

}

else
{
}

}

Error Line:

ipaddress =Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

Error message:
  "Use of unassigned local variable 'Request' "

anybody knows to solve this issue and get the visitors location using ip address.

regards
sasi


Answers (2)