Solved

How to get an IPAddress from within a CodeBehind aspx page

Posted on 2012-03-12
6
198 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

21 Experts available now in Live!

Get 1:1 Help Now