Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:17:17+00:00 2026-06-04T05:17:17+00:00

I Use this code to get the public IP-address (thanks to this post How

  • 0

I Use this code to get the public IP-address (thanks to this post How to get the IP address of the server on which my C# application is running on?):

    public static string GetPublicIP()
    {
        try
        {
            String direction = "";
            WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
            using (WebResponse response = request.GetResponse())
            {
                using (StreamReader stream = new StreamReader(response.GetResponseStream()))
                {
                    direction = stream.ReadToEnd();
                }
            }

            //Search for the ip in the html
            int first = direction.IndexOf("Address: ") + 9;
            int last = direction.LastIndexOf("</body>");
            direction = direction.Substring(first, last - first);

            return direction;
        }
        catch (Exception ex)
        {
            return "127.0.0.1";
        }
    }

But no matter who that access my website, they all get the same IP, and it is the server public IP, not the current user’s IP.

Is it possible to run the WebRequest in context of the current user, not as the server?

Or is the problem that I run this function inside App_Code so that the current user Request is not available, instead it use the server context?

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:17:18+00:00Added an answer on June 4, 2026 at 5:17 am

    Since you are making the request from the server you will get the server’s IP address.

    I am not sure what sort of service you have. In the case of a WCF service, you can grab the IP address from the IncomingMessageProperties of the OperationContext object for the request. See an example here: Get the Client’s Address in WCF

    [ServiceContract]
    public interface IMyService
    {
        [OperationContract]
        string GetAddressAsString();
    }
    
    public class MyService : IMyService
    {
        public string GetAddressAsString()
        {
            RemoteEndpointMessageProperty clientEndpoint =
                OperationContext.Current.IncomingMessageProperties[
                RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    
            return String.Format(
                "{0}:{1}",
                clientEndpoint.Address, clientEndpoint.Port);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why do I get this error message with this code? Use of undeclared identifier
I get this exception in my code: ...IllegalArgumentException...Cant use FLAG_RECEIVER_BOOT_UPGRADE here... Looking into the
In code: //I know that to get this effect (being able to use it
use this code, in the Preferences activity, to know when the reset preference has
I use this code to redirect user to a particular app in the Market:
i use this code for exporting gridview to Excel in asp.net - c# .....but
I use this code on my wordpress plugin to return the src of the
I use this code: $(img.cloudcarousel).each(function(i, e){ coords[i] = $(e).offset(); }); to save the position
I use this code to update data in database table. Can reuse same code
I had a doubt which is the following: When I use the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.