Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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
Posted
Updated 27-Jul-11 22:08pm
v2

This is the first time in my life I have seen Request being defined as local variable. You better read and understand about it first.

http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx

Anyways, you should be able to fix it yourself once you understand how it works. If you still have doubts, get back here and someone will surely help you. Good Luck.
 
Share this answer
 
Comments
ramuksasi 28-Jul-11 4:20am    
sorry Bhardwaj..
i am newer to the .net. And i dont know how to do it. i am learning myself in the way of referring web materials.
C#
System.Web.HttpRequest Request;
ipaddress =Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

You have defined Request but you have not initialized it, hence your "unassigned variable" message.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900