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
Loading
Sasikumar SPosted Jul 28, 2011, 4:33 AM
I solved my problem, actually no need to use that two line in application. Unknowingly i asked unnecessary question. sorry to say that..
regards
sasi
Zoran HorvatPosted Jul 28, 2011, 4:21 AM
System.Web.HttpRequest Request;
ipaddress =Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Instead, read variables as:
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Zoran