Gupta Ji
Gupta Ji

Reputation:

User authentication in asp.net or mvc

How do I check if the user changed their IP address by calling a method in ASP.Net?

Upvotes: 0

Views: 948

Answers (3)

Henry Gao
Henry Gao

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

Joseph
Joseph

Reputation: 25513

You can use:

Request.UserHostAddress()

Upvotes: 3

Craig Bart
Craig Bart

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

Related Questions