我想保存注册我的应用程序的客户的ips [英] I want to save the ips of the customers who registers with my application

查看:133
本文介绍了我想保存注册我的应用程序的客户的ips的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存注册了我的应用程序的客户的IP并将他们的ips保存到数据库中。在我的情况下,我的开发服务器ip保存到db



我尝试了什么:



var ip = HttpContext.Connection.RemoteIpAddress



保存我的开发服务器的ip。

I want to save the IP of the customers who registers with my application and save theirs ips into database.In my case my dev server ip is saving into db

What I have tried:

var ip = HttpContext.Connection.RemoteIpAddress

its saves the ip of my dev server.

推荐答案

简答:

Short Answer:
private string GetUserIP()
    {
        string ipList = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (!string.IsNullOrEmpty(ipList))
        {
            return ipList.Split(',')[0];
        }

        return Request.ServerVariables["REMOTE_ADDR"];
    }



参考: c# - 如何获取用户的客户端ASP.NET中的IP地址? - 堆栈溢出 [ ^ ]



长答案:阅读以下讨论,特别是那些票数巨大的讨论。

c# - 如何在ASP.NET中获取用户的客户端IP地址? - 堆栈溢出 [ ^ ]



希望,有帮助:)


reference: c# - How to get a user's client IP address in ASP.NET? - Stack Overflow[^]

Long Answer: Read the below discussion, specially those with huge up votes.
c# - How to get a user's client IP address in ASP.NET? - Stack Overflow[^]

Hope, it helps :)


检查您的开发服务器是:通常在开发中它在您的机器上,因此它确实具有与客户端相同的IP地址!



请注意,在Web应用程序中, IP地址不是个人客户端计算机 - 它将是他连接的路由器的IP,因此整个办公室将共享相同的IP地址,就服务器而言。

请注意,大多数IP地址都不是静态的 - 它们可以在每次设备连接时更改,因此将它们用作安全机制并不能可靠地工作,如果这是您的意图。
Check where your dev server is: normally in development it's on your machine, so it will indeed have the same IP address as the client!

Be aware that in web applications, the IP address will not be individual to a client computer - it will be the IP of the router via which he connects, so an entire office will share the same IP address as far as your server is concerned.
And be aware that most IP addresses aren't static - they can change each time the device is connected, so using them as a security mechanism isn't going to work reliably, if that was your intent.


String IP = HttpContext.Current.Request.ServerVariables [HTTP_X_FORWARDED_FOR];



if(string.IsNullOrEmpty( IP))

IP = HttpContext.Current.Request.ServerVariables [REMOTE_ADDR];
String IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (string.IsNullOrEmpty(IP))
IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];


这篇关于我想保存注册我的应用程序的客户的ips的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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