code file for that solution is below,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
DataClassesDataContext obj = new DataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
string ipaddress;
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipaddress == "" || ipaddress == null)
ipaddress = Request.ServerVariables["REMOTE_ADDR"];
ipaddress = "27.121.103.12";
XmlTextReader XmlRdr = GetLocation(ipaddress);
if (XmlRdr != null)
{
while (XmlRdr.Read())
{
if (XmlRdr.Name.ToString() == "cityName")
{
lblCity.Text = XmlRdr.ReadString().Trim();
}
if (XmlRdr.Name.ToString() == "regionName")
{
lblRegion.Text = XmlRdr.ReadString().Trim();
}
if (XmlRdr.Name.ToString() == "countryName")
{
lblCountry.Text = XmlRdr.ReadString().Trim();
}
if (XmlRdr.Name.ToString() == "countryCode")
{
lblCountryCode.Text = XmlRdr.ReadString().Trim();
}
if (XmlRdr.Name.ToString() == "longitude")
{
lblLong.Text = XmlRdr.ReadString().Trim();
}
if (XmlRdr.Name.ToString() == "latitude")
{
lblLat.Text = XmlRdr.ReadString().Trim();
}
if (XmlRdr.Name.ToString() == "timeZone")
{
lblTime.Text = XmlRdr.ReadString().Trim();
}
lblIP.Text = ipaddress;
}
XmlRdr.Close();
}
else
{
lblIP.Text = "IP not Detected";
}
}
private XmlTextReader GetLocation(string ipaddress)
{
string myKey = "Your Api key Here";
WebRequest rssReq = WebRequest.Create("http://api.ipinfodb.com/v3/ip-city/?key=" + myKey + "&ip=" + ipaddress + "&format=xml");
WebProxy px = new WebProxy("http://api.ipinfodb.com/v3/ip-city/?key=" + myKey + "&ip=" + ipaddress + "&format=xml", true);
rssReq.Proxy = px;
rssReq.Timeout = 2000;
try
{
WebResponse rep = rssReq.GetResponse();
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
return xtr;
}
catch
{
return null;
}
}
}
thats great solution.....
Thnx & Regards,
PKriyshnA="PriyA+KrishnA"; :)