Reputation:
How do I check if the user changed their IP address by calling a method in ASP.Net?
Upvotes: 0
Views: 948
Reputation: 4936
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).
Upvotes: 1
Reputation: 75
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();
}
}
Upvotes: 3