Solved

How to get an IPAddress from within a CodeBehind aspx page

Posted on 2012-03-12
6
199 Views
Last Modified: 2012-06-27
I am trying to get the users IPAddress....from within a CodeBehind aspx page.

This is on my aspx page... test.aspx
which refers to --> CodeBehind="test.aspx.vb"

My function is this.....(inside test.aspx.vb)
    Public Shared Function getIPAddress()
        Dim IPAddress As String = ""
        IPAddress = Request.ServerVariables("REMOTE_ADDR")
        Return IPAddress
    End Function

The error I get is this.....
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Can I get the IPAddress directly from inside the CodeBehind page?
Can I get it from the aspx page & pass it to the CodeBehind page?
0
Comment
Question by:MikeCombe
  • 3
  • 2
6 Comments
 
LVL 4

Accepted Solution

by:
veera earned 250 total points
ID: 37712963
Hi,

try this

Dim strClientIp As String = Request.UserHostAddress()

OR

Dim strClientIP As String = HttpWorkerRequest.GetRemoteAddress().ToString()

OR

Dim strClientIP As String = Context.Request.ServerVariables("REMOTE_ADDR")
0
 

Author Comment

by:MikeCombe
ID: 37713120
same error....using

    Public Shared Function getIPAddress()
        Dim IPAddress As String = ""
        IPAddress = Request.UserHostAddress()
        IPAddress = HttpWorkerRequest.GetRemoteAddress().ToString()
        IPAddress = Context.Request.ServerVariables("REMOTE_ADDR")
        Return IPAddress
    End Function
0
 
LVL 16

Assisted Solution

by:Rose Babu
Rose Babu earned 250 total points
ID: 37713368
This will work correctly.
Dim IPAddress As String = ""
IPAddress = Request.UserHostName

Open in new window

Try this.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:MikeCombe
ID: 37713961
nope.....same error. see attached graphic.
IPAddress.png
0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37714784
May i know, Why did you declare the getIPAddress() function as a shared function?
Public Function getIPAddress()
        Dim IPAddress As String = ""
        IPAddress = Request.UserHostName
        Return IPAddress
End Function

Open in new window

Can u make the function as non-shared function and test once?
0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37756781
any luck?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
New to Angular (read tutorial) - How do I bind to this table? 11 45
Error in page 3 46
Class object 2 27
Data is not showing from images 15 38
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now