Click here to Skip to main content
15,906,467 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to view a table using the Data Grid View Pin
carlecomm6-Jan-10 15:51
carlecomm6-Jan-10 15:51 
GeneralRe: How to view a table using the Data Grid View Pin
Jeff Patterson6-Jan-10 17:05
Jeff Patterson6-Jan-10 17:05 
QuestionList open Excel files Pin
Akash Patki5-Jan-10 16:35
Akash Patki5-Jan-10 16:35 
AnswerRe: List open Excel files Pin
dojohansen7-Jan-10 6:08
dojohansen7-Jan-10 6:08 
GeneralRe: List open Excel files Pin
Akash Patki7-Jan-10 7:11
Akash Patki7-Jan-10 7:11 
Questioncrystal Reports problem? Pin
miss YY5-Jan-10 14:47
miss YY5-Jan-10 14:47 
AnswerRe: crystal Reports problem? Pin
Garth J Lancaster5-Jan-10 16:00
professionalGarth J Lancaster5-Jan-10 16:00 
Questiongetting country location based on IP address [modified] Pin
uglyeyes5-Jan-10 14:30
uglyeyes5-Jan-10 14:30 
Hey,

I am running into a weird problem. I am using below method to extract country location based on IP address.

  if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                //To get the IP address of the machine and not the proxy
                m_IPAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
            {
                m_IPAddress = HttpContext.Current.Request.UserHostAddress;
            }
            DataTable dt = GetLocation(m_IPAddress);
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                     m_IPCountry = dt.Rows[0]["City"].ToString() + "," + dt.Rows[0]["RegionName"].ToString() + "," + dt.Rows[0]["CountryName"].ToString() + "," + 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;
            }
        }

when i try to catch the exception i get error msg "The remote server returned an error: (503) Server Unavailable."

the website is hosted in australia. I am logging all the details in database. IP address is correct at all time just after midnight in australia i am able to get country information while during the day it becomes null. any idea what am i doing wrong. probably need to add something in web.config?

modified on Tuesday, January 5, 2010 8:47 PM

AnswerRe: getting country location based on IP address Pin
Garth J Lancaster5-Jan-10 15:51
professionalGarth J Lancaster5-Jan-10 15:51 
GeneralRe: getting country location based on IP address Pin
uglyeyes5-Jan-10 18:05
uglyeyes5-Jan-10 18:05 
GeneralRe: getting country location based on IP address Pin
Garth J Lancaster5-Jan-10 18:09
professionalGarth J Lancaster5-Jan-10 18:09 
GeneralRe: getting country location based on IP address Pin
Garth J Lancaster5-Jan-10 18:16
professionalGarth J Lancaster5-Jan-10 18:16 
GeneralRe: getting country location based on IP address Pin
uglyeyes6-Jan-10 9:07
uglyeyes6-Jan-10 9:07 
GeneralRe: getting country location based on IP address Pin
uglyeyes6-Jan-10 10:57
uglyeyes6-Jan-10 10:57 
GeneralRe: getting country location based on IP address Pin
uglyeyes12-Jan-10 15:41
uglyeyes12-Jan-10 15:41 
AnswerRe: getting country location based on IP address Pin
Ravi Sant14-Apr-11 1:50
Ravi Sant14-Apr-11 1:50 
GeneralThoughts on CrystalReports Pin
SusanP15-Jan-10 14:04
SusanP15-Jan-10 14:04 
GeneralRe: Thoughts on CrystalReports Pin
DaveyM695-Jan-10 14:32
professionalDaveyM695-Jan-10 14:32 
GeneralRe: Thoughts on CrystalReports Pin
SusanP15-Jan-10 14:36
SusanP15-Jan-10 14:36 
QuestionCryptographic Service Provider: How Do I Secure Machine-Level RSA Key Containers? Pin
Skippums5-Jan-10 11:58
Skippums5-Jan-10 11:58 
QuestionFile already Loaded, Save Pin
San245-Jan-10 9:33
San245-Jan-10 9:33 
AnswerRe: File already Loaded, Save Pin
Not Active5-Jan-10 9:45
mentorNot Active5-Jan-10 9:45 
AnswerRe: File already Loaded, Save Pin
Skippums5-Jan-10 12:12
Skippums5-Jan-10 12:12 
QuestionStreams and Cryptography (Padding is invalid and cannot be removed) Pin
Skippums5-Jan-10 9:26
Skippums5-Jan-10 9:26 
GeneralRe: Streams and Cryptography (Padding is invalid and cannot be removed) Pin
Skippums5-Jan-10 9:40
Skippums5-Jan-10 9:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.