Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get an IPAddress from within a CodeBehind aspx page

Posted on 2012-03-12
6
Medium Priority
?
207 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 750 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 750 total points
ID: 37713368
This will work correctly.
Dim IPAddress As String = ""
IPAddress = Request.UserHostName

Open in new window

Try this.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

670 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