var requestURL = http://api.hostip.info/?ip=;
function GetLocation4IP(str)
{
requestURL=requestURL+str;
var xmlhttp=false;
try
{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.open("GET",requestURL,true);
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//alert(xmlhttp.responseText);
// code for IE
if (window.ActiveXObject)
{
var doc=new ActiveXObject("Microsoft.XMLDOM");
doc.async="false";
doc.loadXML(xmlhttp.responseText);
}
// code for Mozilla, Firefox, Opera, etc.
else
{
var parser=new DOMParser();
var doc=parser.parseFromString(xmlhttp.responseText,"text/xml");
}// documentElement always represents the root node
var myXML=doc.documentElement;
var city=myXML.childNodes[3].childNodes[0].childNodes[0].childNodes[0].nodeValue;
var country=myXML.childNodes[3].childNodes[0].childNodes[1].childNodes[0].nodeValue;
var coord;
var longitude="";
var latitude="";
var display;
//display=city+""+country;
if(city!="(Private Address)")
{
coord=myXML.childNodes[3].childNodes[0].childNodes[4].childNodes[0].childNodes[0].childNodes[0].childNodes[0].nodeValue;
var coordinates=coord.split(',')
longitude=coordinates[0];
latitude=coordinates[1];
//display+=""+longitude+""+latitude;
}
display=city+""+country+""+longitude+""+latitude;
document.write(display);
}
}
xmlhttp.send(null);
}
Monday, February 26, 2007
Tuesday, February 20, 2007
Locate IP & Get data from Server output(HTML) in ASP.NET
Using C#
----------------
using System.Net;
using System.Text;
Source Code:
-------------
// Page URL to get information
const string strUrl = "http://www.ip2location.com/ib1/";
byte[] reqHTML;
string ip_Info_Dtl;
WebClient webClient = new WebClient();
reqHTML = webClient.DownloadData(strUrl);
UTF8Encoding objUTF8 = new UTF8Encoding();
ip_Info_Dtl = objUTF8.GetString(reqHTML);
----------------
using System.Net;
using System.Text;
Source Code:
-------------
// Page URL to get information
const string strUrl = "http://www.ip2location.com/ib1/";
byte[] reqHTML;
string ip_Info_Dtl;
WebClient webClient = new WebClient();
reqHTML = webClient.DownloadData(strUrl);
UTF8Encoding objUTF8 = new UTF8Encoding();
ip_Info_Dtl = objUTF8.GetString(reqHTML);
Handling "Thread was being aborted" error in ASP.NET
Handling "Thread was being aborted" error in ASP.NET
This error occurs when you have used the following statements in code behind
due to the execution of Response.End() method.
1) Response.Redirect()
2) Server.Transfer()
3) Response.End()
Because the (1) & (2) statements internally executes Response.End().
To overcome this error
1) Response.Redirect(URL,false);
2) Give this statements within
try { }
catch { }
3) Use HttpContext.Current.ApplicationInstance.CompleteRequest() method
Instead of Response.End()
This error occurs when you have used the following statements in code behind
due to the execution of Response.End() method.
1) Response.Redirect()
2) Server.Transfer()
3) Response.End()
Because the (1) & (2) statements internally executes Response.End().
To overcome this error
1) Response.Redirect(URL,false);
2) Give this statements within
try { }
catch { }
3) Use HttpContext.Current.ApplicationInstance.CompleteRequest() method
Instead of Response.End()
Subscribe to:
Posts (Atom)