views:

218

answers:

3

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
+1  A: 

You can use:

Request.UserHostAddress()
Joseph
i say for check user change his ip or not means to say any user change his ip for our site or not
You would store that IP associated with the user's identity, and then compare it later.
Joseph
+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