Solved

How to get an IPAddress from within a CodeBehind aspx page

Posted on 2012-03-12
6
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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