Find user's IP address in project

manared

Well-known member
Joined
Jun 1, 2006
Messages
84
Programming Experience
1-3
I am creating an http module in a project that is referenced and called by a plain web application (in vb.net). I want to find out what each user's IP address is that opens the email that I am sending them. There is an id in the email that calls the web application to run and that's how everything gets started. What I don't know right now is how to find the IP address. Does anyone know how to do that in a project? Thank you!!!
 
Add event handler for HttpApplication.BeginRequest, the object is given by context parameter of the IHttpModules Init implementation. Each request will expose the UserHostAddress. Example:
VB.NET:
Public Class Class1
    Implements IHttpModule
 
    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
    End Sub
 
    Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
        AddHandler context.BeginRequest, AddressOf context_BeginRequest
    End Sub
 
    Private Sub context_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs) 
        Dim app As HttpApplication = CType(sender, HttpApplication)
        Dim strAddress As String = app.Request.UserHostAddress
    End Sub
End Class
 
Back
Top