get user ip address not deployment system ip address

RAVI 1,056 Reputation points
2024-07-10T07:54:33.8233333+00:00

Hello

I want to get and show in Label1 user system name and ip address not deployment machine ip address how to get that

i tried this but its taking depoyment ip address i want user machine ip

  string hostName = Dns.GetHostName();
        Console.WriteLine(hostName);

        // Get the IP from GetHostByName method of dns class. 
        string IP = Dns.GetHostByName(hostName).AddressList[0].ToString();
        Label2.Text = IP;

Thanks

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,504 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 29,746 Reputation points Microsoft Vendor
    2024-07-10T08:57:10.0233333+00:00

    Hi @RAVI,

    Try both :

    HttpContext.Current.Request.UserHostAddress;
    

    or

    HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.