如何检索用户客户端的IP地址并插入数据库? [英] how can i retrieve IP Address of user client and insert into the database?
问题描述
您好。
我已经使用sqlserver 2008通过Asp.net4制作了一个Web应用程序,我希望在登录页面中
检索用户IP地址并将其插入到DATEBASE。有可能吗?我该怎么做(代码是什么)?
注意:我工作的部门,所有PC都在网络状态下连接
Hello.
I have made a web application by Asp.net4 with sqlserver 2008, i i would like in login page
retrieve user IP Address and insert it into the datebase. is it possible & how can i do that (what is it code)?
Note: the departemant where i work, all PC are connected within a network state
推荐答案
看看这个
Have a look at this
string ip = Server.HtmlEncode(Request.UserHostAddress);
这将为您提供ip作为字符串
。你可以把它插入数据库。
注意:
你会的如果你从localhost运行它,每次都得到127.0.0.1。
问候..:笑:
This will give you ip as a string
. You can insert it into database.
Note:
You will get 127.0.0.1 every time if you run it from localhost.
Regards..:laugh:
你可以得到用户IP地址:
You can get user IP address by:
Request.ServerVariables("REMOTE_ADDR")
或,
or,
Request.UserHostAddress
也可以查看这些..
http://stackoverflow.com/questions/735350/how-to-get-a-users-client- ip-address-in-asp-net [ ^ ]
http://stackoverflow.com/qu estions / 7737499 / get-ip-address-of-user-computer-in-c-sharp [ ^ ]
获取IP地址后,您可以将其插入数据库。我假设你知道如何在数据库中插入数据。
Also can view these..
http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net[^]
http://stackoverflow.com/questions/7737499/get-ip-address-of-user-computer-in-c-sharp[^]
After fetching IP address you can inset it into database.I assume you know how to insert data in database.
这篇关于如何检索用户客户端的IP地址并插入数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!