I am running an application that has to get the current user IP address, the functionality seems to be working when running the app from VS, however it breaks completely when deployed on IIS, here is the code to get the user IP
public static string GetUserIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return ipEntry.AddressList.Last().ToString();
}
I have another method which uses the return value from the GetUserIP() method, here is the code
private void SaveSmsDetails(string cellNumber, string message, string userLogonName)
{
string[] userIP = IPAddressGetter.GetUserIP().Split('.');
}
Now this method is throwing a an index out of range exception, this means the GetUserIP method does not returning any value hence the Split method is falling apart, is there anything I need to do or change or perhaps something must be done on the IIS server. Note: IIS version is 8.5.9