Wednesday, June 22, 2022

How to get IP address in C# ASP.NET

 public string IPAddr()

    {

        try

        {



            string ipaddress;


            ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];


            if (ipaddress == "" || ipaddress == null)


                ipaddress = Request.ServerVariables["REMOTE_ADDR"];


            return ipaddress;


        }

        catch (Exception ex)

        {

            ExceptionHandler.WriteException(ex.Message);

        }

        return null;

    }

No comments:

Post a Comment