Trapping IP address

Discussion in 'ASP .Net' started by Zach, Jun 1, 2012.

  1. Zach

    Zach Guest

    I was looking for code to trap the visitor's IP address and found the
    following:
    Partial Class IP_Address
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load
    Dim nowip As String
    nowip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If nowip = "" Then
    nowip = Request.ServerVariables("REMOTE_ADDR")
    End If
    If txtIPAddress.Text = "" Then
    txtIPAddress.Text = nowip
    End If
    End Sub
    End Class
    ......
    Translating into C#, I ran into problems;
    for a start the using isn't recognized:

    I tried:

    using System.Web.UI.Page;
    // blabla
    string nowip = Request.ServerVariables("HTTP_X_FORWARDED_FOR");
    if(nowip == stringEmpty) nowip = Request.ServerVariables("REMOTE_ADDR");
    string ip_address = " the visitor's IP address is: " + nowip;

    This corde produces errors;
    could you please help to get it right?
    Zach.
     
    Zach, Jun 1, 2012
    #1
    1. Advertising

  2. Zach

    Zach Guest

    "Zach" <> wrote in message
    news:4fc8f1ef$0$14711$...

    If anyone is interested, this is what the code should be like.

    Zach.

    string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (ipAddress == null || ipAddress == "")
    {
    ipAddress = Request.ServerVariables["REMOTE_ADDR"];
    }
     
    Zach, Jun 1, 2012
    #2
    1. Advertising

  3. Zach

    Arne Vajhøj Guest

    On 6/1/2012 3:03 PM, Zach wrote:
    > If anyone is interested, this is what the code should be like.


    > string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    > if (ipAddress == null || ipAddress == "")
    > {
    > ipAddress = Request.ServerVariables["REMOTE_ADDR"];
    > }


    Yes. C# uses [] for indexers.

    Arne
     
    Arne Vajhøj, Jun 2, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avnrao
    Replies:
    1
    Views:
    7,341
    avnrao
    May 4, 2004
  2. Patrice
    Replies:
    0
    Views:
    925
    Patrice
    May 4, 2004
  3. Raterus
    Replies:
    0
    Views:
    465
    Raterus
    Jun 2, 2004
  4. Alex Stevens
    Replies:
    0
    Views:
    808
    Alex Stevens
    Aug 10, 2004
  5. =?Utf-8?B?QW5nZWw=?=

    Pass a Web Address and return a File System Address

    =?Utf-8?B?QW5nZWw=?=, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    560
    =?Utf-8?B?U3RldmUgQy4gT3Jy?=
    Sep 21, 2005
Loading...

Share This Page