Methods for asp.net to obtain a true ip
- 2021-06-29 10:46:45
- OfStack
This paper gives an example of how asp.net acquires a true ip.Share it for your reference.Specifically as follows:
public string getip()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
I hope that the description in this paper will be helpful to everyone's asp.net program design.