Avatar of MikeCombe
MikeCombe
Flag for United States of America asked on

How to get an IPAddress from within a CodeBehind aspx page

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?
ASP.NET

Avatar of undefined
Last Comment
Rose Babu

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
pvr

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MikeCombe

ASKER
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
SOLUTION
Rose Babu

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MikeCombe

ASKER
nope.....same error. see attached graphic.
IPAddress.png
Rose Babu

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?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Rose Babu

any luck?