Results 1 to 4 of 4

Thread: Routing table

  1. #1
    .NET Framework
    .NET 3.5
    Join Date
    Oct 2010
    Posts
    3
    Reputation
    0

    Routing table

    Hello everyone,

    I would like to know how to get the IP routing table of a client that is accessing an aspx file via internet (written in Vb.net) to be used later on.
    Actually when a client calls my aspx file, I want to register his IP (it should be an IP table, as I know), in order to be able to access him later on for data update ,I think this is called push notification or push message.

    Anyone can help ?

    Thanks
    Rony

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,501
    Reputation
    1038
    If you're stuck on getting the client's IP address here's this:
    Imports System
    Imports System.Web

    Module IP
    Function GetIPAddress() As String
    Return GetIPAddress(New HttpRequestWrapper(HttpContext.Current.Request))
    End Function

    Friend Function GetIPAddress(ByVal request As HttpRequestBase) As String
    Dim forwarded As String = request.Headers("Forwarded")

    If Not String.IsNullOrEmpty(forwarded) Then

    For Each segment As String In forwarded.Split(","c)(0).Split(";"c)
    Dim pair As String() = segment.Trim().Split("="c)

    If pair.Length = 2 AndAlso pair(0).Equals("for", StringComparison.OrdinalIgnoreCase) Then
    Dim ip As String = pair(1).Trim(""""c)
    Dim left As Integer = ip.IndexOf("["c), right As Integer = ip.IndexOf("]"c)

    If left = 0 AndAlso right > 0 Then
    Return ip.Substring(1, right - 1)
    End If

    Dim colon As Integer = ip.IndexOf(":"c)

    If colon <> -1 Then
    Return ip.Substring(0, colon)
    End If

    Return ip
    End If
    Next
    End If

    Dim xForwardedFor As String = request.Headers("X-Forwarded-For")

    If Not String.IsNullOrEmpty(xForwardedFor) Then
    Return xForwardedFor.Split(","c)(0)
    End If

    Return request.UserHostAddress
    End Function
    End Module
    Just add it to your project as a new class and call it:
    IP.GetIPAddress()
    As for the push notifications that's something I haven't had a need to learn how to do yet.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

  3. #3
    .NET Framework
    .NET 3.5
    Join Date
    Oct 2010
    Posts
    3
    Reputation
    0
    Thanks for your help.
    However, what library should I import as the types "HttpRequestWrapper" and "HttpRequestBase" are not defined.

    Actually I have the below libraries in my project and still not defined:

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Web
    Imports System.Collections.Specialized
    Imports System.Net
    Imports System.Text
    Imports System.IO
    Last edited by dibrony; 10-29-2018 at 4:04 PM.

  4. #4
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    14,002
    Reputation
    1730
    Quote Originally Posted by dibrony View Post
    Thanks for your help.
    However, what library should I import as the types "HttpRequestWrapper" and "HttpRequestBase" are not defined.
    That's not a question that you ever need to ask. Every public type in the Framework is documented and the documentation for every type specifies what assembly it is declared in and what namespace it's a member of. You also ought to learn the difference between a namespace and an assembly because that list you provided are not libraries. I suggest that you follow the Blog link in my signature below and check out my post on Assemblies & Namespaces.

Similar Threads

  1. Getting Started - The URL Routing
    By libron in forum MV*
    Replies: 1
    Last Post: 11-02-2012, 10:15 AM
  2. Replies: 2
    Last Post: 03-26-2009, 1:11 AM
  3. Replies: 1
    Last Post: 02-20-2009, 5:37 AM
  4. Add x number of fields from table aaa to the end of table bbb
    By JDMils in forum Database General Discussion
    Replies: 0
    Last Post: 03-06-2006, 6:48 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •