Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

There is a post request coming to my portal and I am fetching IP address from the post request on my portal landing page(INDEX view in MVC) and saving in DB table. below is the code to fetch IP address.

C#
string Device_IP = "";
if (!string.IsNullOrEmpty(Request.ServerVariables["HTTP_VIA"]))
{
//           ' using proxy
//          ' Return real client IP.            
    Device_IP = Convert.ToString(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
}
else
{
//    'not using proxy or can't get the Client IP
//    'While it can't get the Client IP, it will return proxy IP.
                Device_IP = Convert.ToString(Request.ServerVariables["REMOTE_ADDR"]);
}


It is fetching IP address on my side but on client side when request is made code is not working. same code working fine on other sites.

what are the possible causes and solution for this issue?

Thanks.
Posted
Updated 17-Dec-15 19:34pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900