Suppose you want to get details of users who visited the contact page in your website. Then,in
Page_Load
event of the contact page just put the single line as below:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string ip = Server.HtmlEncode(Request.UserHostAddress);
}
}
This will give you ip as a string. You can insert it into database wherever you want.
Note:
You will get 127.0.0.1 every time if you run it from localhost.
Regards.:)