Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

C#
public void GetLoginIP()
    {
        try
        {
            String strIP = "";
            WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
            using (WebResponse response = request.GetResponse())
            using (StreamReader stream = new StreamReader(response.GetResponseStream()))
            {
                strIP = stream.ReadToEnd();
            }
            int first = strIP.IndexOf("Address: ") + 9;
            int last = strIP.LastIndexOf("</body>");
            strIP = strIP.Substring(first, last - first);

            Session["IP"] = strIP;
        }
        catch(Exception Ex)
        {

        }

    }


The site is too slow when working above code when it host in Germany region...how can i make it work fast
Posted
Comments
Thanks7872 20-Jun-14 7:22am    
What the title has to do with the issue/question?

1 solution

i think this may be the network latency issue. so u can invoke above functionlity once on application startup and stores somewhere.. so u dont need to fetch it every time



C#
public static void GetLoginIP()
    {
        try
        {
            if(Session["IP"] == null)
{
            String strIP = "";
            WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
            using (WebResponse response = request.GetResponse())
            using (StreamReader stream = new StreamReader(response.GetResponseStream()))
            {
                strIP = stream.ReadToEnd();
            }
            int first = strIP.IndexOf("Address: ") + 9;
            int last = strIP.LastIndexOf("</body>");
            strIP = strIP.Substring(first, last - first);

            Session["IP"] = strIP;
}
        }
        catch(Exception Ex)
        {

        }

    }
 
Share this answer
 
Comments
Sajith Koleri 20-Jun-14 7:35am    
Hi,
Thanks for the reply...but there will be initial slowness , can u suggest any idea for avoiding it.
ashok rathod 20-Jun-14 9:06am    
you can actually run above code in seperate thread parallel to your application using BackgroundWorker.But here problem will be that you if meanwhile u needs to use IP one or other place you wont get untill backgroundworker process is not completed.

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