如何使用.net获取用户的IP地址?

Sur*_*har 5 c# asp.net

在我的网络应用程序中,我有注册表,当用户注册我想获得他的系统的IP地址,我怎么能使用asp.net.请帮帮我.

Lan*_*per 9

HttpContext.Current.Request.UserHostAddress; 
Run Code Online (Sandbox Code Playgroud)

要么

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
Run Code Online (Sandbox Code Playgroud)

要获取计算机的IP地址而不是代理,请使用以下代码

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Run Code Online (Sandbox Code Playgroud)