本文介绍了我想保存注册我的应用程序的客户的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.

推荐答案

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

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

        return Request.ServerVariables["REMOTE_ADDR"];
    }



参考: []



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

[]



希望,有帮助:)


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 :)




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

09-02 21:32