Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to retrieve value from request header X-FORWARDED-FOR its always returning null, can someone tell me how can we get the value of X-FORWARDED-FOR. Actually I need original(public) ip address of client system

What I have tried:

I am trying to retrieve value from request header X-FORWARDED-FOR its always returning null, can someone tell me how can we get the value of X-FORWARDED-FOR. Actually I need original ip address of client system
Posted
Updated 9-Aug-17 2:21am
Comments
David_Wimbley 8-Aug-17 16:17pm    
Can you provide a code sample of how you are attempting to get the value? We don't have access to your code so we don't know what it is you have tried that is causing you to always get null values.
Code_seeker_ 8-Aug-17 16:45pm    
Here is my code, do I need to make any changes at IIS level to get X FORWARDED FOR value ?
string strIpAddress;
strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIpAddress == null)
{
strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}
REMOTE ADDRE giving me local IP address which I don't need, all I need is public IP address.
F-ES Sitecore 9-Aug-17 8:31am    
That's an optional header, are you sure it's there? There is no sure way to get the client IP address so my advice is to not design anything where the client IP is needed.
Code_seeker_ 27-Aug-17 14:46pm    
Then how can I achieve white list IPs for my application

1 solution

There is a difference between ServerVariables[^] and Headers[^]...
You should look for it in the later...
 
Share this answer
 

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