0

i have used the ASP.NET with C# . i want to check how many client send request to the web server . i have deploy the web page in IIS server then when i have accessed this site from the another computer using IP address of the IIS web server .

How to count no. clients connected to the server?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
user847455
  • 781
  • 4
  • 9
  • 22

1 Answers1

0

use the below function to get the IP and log this. Then take the unique IP to find out how many computers connect to your server

public static string GetIPAddress()
{
    System.Web.HttpContext context = System.Web.HttpContext.Current;
    string sIPAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (string.IsNullOrEmpty(sIPAddress)) {
        return context.Request.ServerVariables["REMOTE_ADDR"];
    } else {
        string[] ipArray = sIPAddress.Split(new Char[] { ',' });
        return ipArray[0];
    }
}
PraveenVenu
  • 8,217
  • 4
  • 30
  • 39
  • Yes that is what I meant. Store the IP in the database. Then take count of disctinct IP. – PraveenVenu Feb 29 '12 at 11:53
  • That is because when you access the site from the LAN, you share a common external IP. – PraveenVenu Mar 02 '12 at 12:36
  • i have used this method but when store the ip in array & array stored in application["key"]=array; it increment the count after adding the IP address in array but after the one client close the web browser it will not remove the IP address from the array. how to remove hte IP address from array when this client closed the application . i have write this code in globa.asax add the ip address in session_start event & try to remove the IP in session_end event when remove the IP in session_end event it return null IP address – user847455 Mar 07 '12 at 09:43
  • your counter will not be decremented at closing the browser but when the session end. So in this case, if your session time out is set to 10 minutes, 10 minutes after closing the browser the Session_End event will be fired and your counter will be decremented. – PraveenVenu Mar 07 '12 at 11:54
  • but after starting the browser 10 min session_end fired & decrement counter & then after 10 min i will closed the browser then again counter get decreases but only one client connected to the server – user847455 Mar 07 '12 at 12:25