ipaddress, true);
//Assign the proxy to the WebRequest
rssReq.Proxy = px;
//Set the timeout in Seconds for the WebRequest
rssReq.Timeout = 2000;
try
{
//Get the WebResponse
WebResponse rep = rssReq.GetResponse();
//Read the Response in a XMLTextReader
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
//Create a new DataSet
DataSet ds = new DataSet();
//Read the Response into the DataSet
ds.ReadXml(xtr);
return ds.Tables[0];
}
catch
{
return null;
}
}
I got the foll.errorrs& i dnt know wat namespace to use:-
1. The type or namespace name 'WebRequest' could not be found (are you missing a using directive or an assembly reference?)
2. The name 'WebRequest' does not exist in the current context
3. The type or namespace name 'WebProxy' could not be found (are you missing a using directive or an assembly reference?)
4. The type or namespace name 'WebProxy' could not be found (are you missing a using directive or an assembly reference?)
5. The type or namespace name 'WebResponse' could not be found (are you missing a using directive or an assembly reference?)
6. The type or namespace name 'XmlTextReader' could not be found (are you missing a using directive or an assembly reference?)
7. The type or namespace name 'XmlTextReader' could not be found (are you missing a using directive or an assembly reference?)
8. The best overloaded method match for 'System.Data.DataSet.ReadXml(System.Xml.XmlReader)' has some invalid arguments
9. Argument '1': cannot convert from 'XmlTextReader' to 'System.Xml.XmlReader'
Wat abt the webservice?I know we can call webservices through webreferences,but which webservice to call, wat to do?? I m confused.plz hlp urgntly.
but wen i put this on my domain www.xxx.com, thn its not showing my local IP,its displaying 127.160.xx.xx while my local IP is 192.xxx.x.xx.All other systems in my LAN also showing the same IP as "127......"
It will not show local IP?thn how can i find the number of unique visitors to my website and many other details???
tdb
Member
116 Points
284 Posts
know the country where my website is opened
May 05, 2009 05:05 AM|LINK
I m using VS2005 & SQL2005.
I hv made a website, I want to know the country where my website is opened??Based on the country name, i want to show some extra feature else not.
I hv used the following code to know hopst name,and its ip address.wen i put it on my domain,it gives server name and its ip.
string strHostName = System.Net.Dns.GetHostName();string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();lblIP.Text = strHostName;
lblIP.Text +=
" " + clientIPAddress;What should I do??
plz tel.
om_prakashp
Contributor
2584 Points
378 Posts
Re: know the country where my website is opened
May 05, 2009 07:36 AM|LINK
Please check the following post:
http://forums.asp.net/t/1416074.aspx
http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo(vs.71).aspx
tdb
Member
116 Points
284 Posts
Re: know the country where my website is opened
May 05, 2009 09:04 AM|LINK
I hv visited these links, but still I m not clear with it.......
i hv also tried this:-
string strHostName = System.Net.Dns.GetHostName();string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();lblIP.Text = strHostName;
lblIP.Text +=
" "+clientIPAddress;lblIP.Text +=
" "+Request.UserHostAddress.ToString();Result On Localhost:
mycomputername my_localIPaddress(192.168.x.xx) 127.0.0.1
Result On my Website:
myservername 192.168.xxx.xxx 122.160.xx.xx
I dont know wat to do??
any other help is highly appreciated.
naveenjoshi
Member
520 Points
92 Posts
Re: know the country where my website is opened
May 05, 2009 10:16 AM|LINK
Give a try to this service:
http://www.ip2location.com/ip2location-dotnet-component.aspx
Naveen Joshi
Always remember to click “Mark as Answer” on the post that helps you.
shahed.kazi
All-Star
17953 Points
3635 Posts
Re: know the country where my website is opened
May 05, 2009 10:40 AM|LINK
I think there is no direct way of achieving this. You will have to rely on some third party service.
.NET World |Captcha Control
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: know the country where my website is opened
May 05, 2009 10:50 AM|LINK
Refer my articles
http://www.aspsnippets.com/post/2009/04/12/Find-Visitors-Geographic-Location-using-IP-Address-in-ASPNet.aspx
http://www.aspsnippets.com/post/2009/04/11/How-to-get-IP-Address-of-Visitors-Machine-in-ASPNet.aspx
Contact me
tdb
Member
116 Points
284 Posts
Re: know the country where my website is opened
May 06, 2009 10:04 AM|LINK
Hi and Thank You everyone!.
Mudassarkhan,
I put the code as u said on ur link:-http://www.aspsnippets.com/post/2009/04/12/Find-Visitors-Geographic-Location-using-IP-Address-in-ASPNet.aspx
protected void Page_Load(object sender, EventArgs e)
{
//Get IP Address
string ipaddress;
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)
{
lblCity.Text = dt.Rows[0]["City"].ToString();
lblRegion.Text = dt.Rows[0]["RegionName"].ToString();
lblCountry.Text = dt.Rows[0]["CountryName"].ToString();
lblCountryCode.Text = dt.Rows[0]["CountryCode"].ToString();
}
else
{
}
}
}
private DataTable GetLocation(string ipaddress)
{
//Create a WebRequest
WebRequest rssReq = WebRequest.Create("http://freegeoip.appspot.com/xml/"
+ ipaddress);
//Create a Proxy
WebProxy px = new WebProxy("http://freegeoip.appspot.com/xml/" +
ipaddress, true);
//Assign the proxy to the WebRequest
rssReq.Proxy = px;
//Set the timeout in Seconds for the WebRequest
rssReq.Timeout = 2000;
try
{
//Get the WebResponse
WebResponse rep = rssReq.GetResponse();
//Read the Response in a XMLTextReader
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
//Create a new DataSet
DataSet ds = new DataSet();
//Read the Response into the DataSet
ds.ReadXml(xtr);
return ds.Tables[0];
}
catch
{
return null;
}
}
I got the foll.errorrs& i dnt know wat namespace to use:-
1. The type or namespace name 'WebRequest' could not be found (are you missing a using directive or an assembly reference?)
2. The name 'WebRequest' does not exist in the current context
3. The type or namespace name 'WebProxy' could not be found (are you missing a using directive or an assembly reference?)
4. The type or namespace name 'WebProxy' could not be found (are you missing a using directive or an assembly reference?)
5. The type or namespace name 'WebResponse' could not be found (are you missing a using directive or an assembly reference?)
6. The type or namespace name 'XmlTextReader' could not be found (are you missing a using directive or an assembly reference?)
7. The type or namespace name 'XmlTextReader' could not be found (are you missing a using directive or an assembly reference?)
8. The best overloaded method match for 'System.Data.DataSet.ReadXml(System.Xml.XmlReader)' has some invalid arguments
9. Argument '1': cannot convert from 'XmlTextReader' to 'System.Xml.XmlReader'
Wat abt the webservice?I know we can call webservices through webreferences,but which webservice to call, wat to do?? I m confused.plz hlp urgntly.
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: know the country where my website is opened
May 06, 2009 10:11 AM|LINK
You need to import these name spaces
using
System;using
System.Data;using
System.Configuration;using
System.Collections;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;using
System.Net;using
System.Xml;Contact me
tdb
Member
116 Points
284 Posts
Re: know the country where my website is opened
May 06, 2009 10:39 AM|LINK
Thank You so much.
but wen i put this on my domain www.xxx.com, thn its not showing my local IP,its displaying 127.160.xx.xx while my local IP is 192.xxx.x.xx.All other systems in my LAN also showing the same IP as "127......"
It will not show local IP?thn how can i find the number of unique visitors to my website and many other details???
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: know the country where my website is opened
May 06, 2009 10:49 AM|LINK
The answer to your question is here Read it
http://www.aspsnippets.com/post/2009/04/11/How-to-get-IP-Address-of-Visitors-Machine-in-ASPNet.aspx
Contact me