Search This Blog

Monday, September 26, 2011

How to get the users IP those who are accessing your website using

Use below code to get the IP of your website users:

<%@ Page Language="C#" %>
<html xmlns="">
<head runat="server">
    <title>Client IP...</title>
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache">

            string _strClientIP = string.Empty;
            string[] _strforwardedIpsList;
            // Get exact IP address if proxy available
            string _strServerVariable = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (!string.IsNullOrEmpty(_strServerVariable))
                _strforwardedIpsList = _strServerVariable.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                _strClientIP = _strforwardedIpsList[_strforwardedIpsList.Length - 1];
                // Get Proxy IP address
                _strClientIP = HttpContext.Current.Request.UserHostAddress;               

                if (string.IsNullOrEmpty(_strClientIP))
                    _strClientIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];


    <form id="testForm">
Post a Comment

Popular Posts