views:

296

answers:

1

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;
        }
+2  A: 

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.

Alex Angas
It can be accessed through Context.Request.UserHostAddress inside a webpart. Thanks
Dan Revell