Daniel Revell
Daniel Revell

Reputation: 8586

How do I find the IP address of a user on SharePoint

I've got a webpart that presents a user on SharePoint with a simple button. On clicking the button I log the user that clicked it, the time and their IP address. The bit I can't figure out is how to find their IP address? Can I get to it through the SharePoint object model or do I have to do something more complicated?

private bool SignInCurrentUser()
        {
            SPWeb web = SPContext.Current.Web;
            SPUser user = web.CurrentUser;
            String address = "?";

            SPList regList = web.Lists["SEED MEng Lab Registration List"];

            SPListItem registration = regList.Items.Add();
            registration["Student"] = user;
            registration["Occurrence"] = DateTime.Now;
            registration["IP Address"] = address;
            registration.Update();

            return true;
        }

Upvotes: 1

Views: 6388

Answers (2)

Amy Struck
Amy Struck

Reputation: 61

Try System.Web.UI.Page.Request.UserHostAddress.

Upvotes: 0

Alex Angas
Alex Angas

Reputation: 60027

I don't think this is exposed by the SharePoint API, however standard ASP.NET techniques (see one and two) should do it.

Try HttpRequest.UserHostAddress.

Upvotes: 2

Related Questions