a blog for those who code

Thursday 26 June 2014

C# : Get Visitor IP Address

In this post we will show you how to get IP Address of the Visitor in C#. The below code snippet will help you to get the Visitor IP address...


Code : 

string GetVisitorIpAddress()
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if(!string.IsNullOrEmpty(ipAddress))
{
string[] ipAddresses = ipAddress.Split(',');
if(ipAddresses.Length != 0)
{
return ipAddresses[0];
}
}
return context.Request.ServerVariables["REMOTE_ADDR"];
}

Please Like and Share the Blog, if you find it interesting and helpful.

1 comment:

  1. Ohayo,

    Allow me to show my gratitude bloggers. You guys are like unicorns. Never seen but always spreading magic. Your content is yummy. So satisfied. ASP .Net

    I want to create a Splitter with a left and a right pane. The right pane should have a fixed size, the left pane should have the rest size of the container div (which has 100% of the width). Unfortunately I can't find an exact documentation how the PaneSize works. The API description for PaneSize Property is "specifies the panesize", this is not very helpful. Can you please give me more information or provide a simple sample.




    Follow my new blog if you interested in just tag along me in any social media platforms!


    Thank you,
    Radhey

    ReplyDelete