Carla Romere
asked on
Client IP Address in Custom MasterPage on Intranet
I have successfully created a custom master page and deployed that on my local machine via deploy from VS2010. It works correctly, changes the master page for all subsites as I wanted. It displays my local ip address correctly as shown on the first screenshot.
Then after much Googling, I managed to create a package from that solution and deploy it on the production server. It also, as expected, replaces all the master pages on the subsites as well. It does display an IP address, but it's the address of the server and not the IP address of the client accessing the server.
It was created with a Control Template and the code for the ip address in that file is:
I need help getting the client's IP address to display on the client's machine whenever they load our intranet SharePoint. We use this for support purposes and is absolutely critical that I get this working correctly.
Then after much Googling, I managed to create a package from that solution and deploy it on the production server. It also, as expected, replaces all the master pages on the subsites as well. It does display an IP address, but it's the address of the server and not the IP address of the client accessing the server.
It was created with a Control Template and the code for the ip address in that file is:
protected void Page_Load(object sender, EventArgs e)
{
string IP4Address = String.Empty;
foreach (IPAddress IPA in Dns.GetHostAddresses(System.Web.HttpContext.Current.Request.UserHostAddress))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
if (IP4Address != String.Empty)
{
//return IP4Address;
}
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
//return IP4Address;
string ip = IP4Address;
myip.Text = "My IP Address is: " + ip;
}
I need help getting the client's IP address to display on the client's machine whenever they load our intranet SharePoint. We use this for support purposes and is absolutely critical that I get this working correctly.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ivan_vagunin: I tried removing that last block of code as you suggested, and then no IP address shows up at all.
And this one:
http://www.4guysfromrolla.com/articles/071807-1.aspx
http://www.4guysfromrolla.com/articles/071807-1.aspx
Does System.Web.HttpContext.Cur rent.Reque st.UserHos tAddress contains correct hostname or client address?
ASKER
Right now it's returning the ip address of the server and I need the ip address of the client.
ASKER
svetaye - The 4guysfromrolla link is exactly the one I used to set this up to begin with. It does give me the ipv4 address, but it's the address of the server. I need the address of the client.
When you get the ipv6 address, this is the address of the server or the client machine?
ASKER
The ipv6 address I assume is the address of the server because when I convert it to ipv4 it's the server.
Ok, so we still have the issue of obtaining the client's IP.
Unfortunately I can't check this on SharePoint server right now. I will check it later. I any case you always have a JavaScript option.
Unfortunately I can't check this on SharePoint server right now. I will check it later. I any case you always have a JavaScript option.
ASKER
Okay - it's working now. It's only showing ipv6 on my local laptop, when I load it from another machine, it's getting the ipv4 address of the remote client. So I think I need to disable ipv6 on my local machine because we are not using it anywhere on our network yet.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great.
ASKER
My final solution was slightly modified from the accepted best solution.
ASKER