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 9019861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:52:25+00:00 2026-06-16T04:52:25+00:00

Here I can use either of these 2 methods. What are the differences and

  • 0

Here I can use either of these 2 methods. What are the differences and which one should I use?

Method 1:

    string srUserIp = "";
    try
    {
        srUserIp = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
    }
    catch
    {

    }

Method 2:

    string srUserIp = "";
    try
    {
        srUserIp = Request.UserHostAddress.ToString();
    }
    catch
    {

    }
  • 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-16T04:52:27+00:00Added an answer on June 16, 2026 at 4:52 am

    Short answer: The two are identical.

    Long answer: To determine the difference between the two use Reflector (or whatever disassembler you prefer).

    The code for the HttpRequest.UserHostAddress property follows:

    public string UserHostAddress
    {
        get
        {
            if (this._wr != null)
            {
                return this._wr.GetRemoteAddress();
            }
            return null;
        }
    }
    

    Note that it returns _wr.GetRemoteAddress(). The _wr variable is an instance of an HttpWorkerRequest object. There are different classes derived from HttpWorkerRequest and which one is used depends on whether you are using IIS 6, IIS 7 or beyond, and some other factors, but all of the ones you would be using in a web application have the same code for GetRemoteAddress(), namely:

    public override string GetRemoteAddress()
    {
        return this.GetServerVariable("REMOTE_ADDR");
    }
    

    As you can see, GetRemoteAddress() simply returns the server variable REMOTE_ADDR.

    As far as which one to use, I’d suggest the UserHostAddress property since is doesn’t rely on “magic strings.”

    Happy Programming

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a few controllers here at work that contain methods I can use
I know I can use placeholder=some text here... but how to make it so
I ask a similar question here and Darin Dimitrov answer that we can't use
I'm hoping someone here can answer these definitively: Does putting a VHD file in
Okay, I need some help here. This is the same old "can't use an
According to the Spring Documentation here : While HTTP defines these four methods, HTML
JS newbie question here: Let's say I have some simple methods for string manipulation,
Hopefully someone here can help me! I'm trying to set up fancybox so when
I hope someone here can help me.. I am currently having a small issue
Hoping some learned Rails developers here can recommend an existing Ruby on Rails plugin

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.