获得C#用户IP [英] get user IP in c#

查看:195
本文介绍了获得C#用户IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要得到用户的IP和使用寿继一table.I'm插入:

I want to get the user IP and insert it in a table.I'm using tho following:

SqlCommand cmd = new SqlCommand("INSERT INTO Raspunsuri Values(@raspuns,@cnp,@data,'1',@ip)", con);
cmd.Parameters.AddWithValue("@cnp", Session["sesiune_cnp"]);
cmd.Parameters.AddWithValue("@raspuns", textbox1.Text);
cmd.Parameters.AddWithValue("@data", DateTime.Now.ToLocalTime());
cmd.Parameters.AddWithValue("@ip", HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);



但是,当我在表中列叶看看我只拿到1 ...你可以给?我一个解释

But when I look in the table at the column Ip i only get 1...can you give me an explanation?

推荐答案

您可以使用:

string ipAddress = Request.UserHostAddress;

这篇关于获得C#用户IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆