How to check user change his ip or not by any method in asp.net or mvc
+1
A:
I use the following to get user ip:
public class UserIp
{
private string _StrIpAddress;
/// <summary>
/// Initializes a new instance of the UserIp class.
/// </summary>
public UserIp()
{
_StrIpAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (_StrIpAddress == null)
_StrIpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
public override string ToString()
{
return base.ToString();
}
}
Craig Bart
2009-11-04 14:18:20
i say for check user change his ip or not means to say any user change his ip for our site or not
2009-11-04 14:27:58
You would store that IP associated with the user's identity, and then compare it later.
Joseph
2009-11-04 15:23:51
+1
A:
System.Web.HttpContext.Current.Request.UserHostAddress can be used to get the IP addess. you can match userid with IP address. you can check either after user login (session_start) or at the begining of each page (page_load method).
Henry Gao
2009-11-04 14:22:44