Search code examples
c#asp.netiiswebserver

.Next count no. clients connected to the server


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?


Solution

  • 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];
        }
    }