ユーザーのIPアドレスを取得することに関するASP.NETの質問
-
02-10-2019 - |
質問
私はこれを使用してIPアドレスを取得しようとしています: -
protected void Page_Load(object sender, EventArgs e)
{
string ClientIP;
ClientIP = HttpContext.Current.Request.UserHostAddress;
Label1.Text = ClientIP;
}
このコードは127.0.0.1を出力します。
そして、以下のコードには何も表示されません!
string ClientIP;
ClientIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Label1.Text = ClientIP;
IPアドレスを取得するにはどうすればよいですか?ユーザーの実際のIPアドレス?
編集
ところで正確な場所は欲しくありません。国を知り、それに応じてユーザーをWebページにリダイレクトする必要があります。
解決
Request.Params["REMOTE_ADDR"]
他のヒント
system.netを使用して、これを試してください -
// Then using host name, get the IP address list..
IPHostEntry ipEntry = DNS.GetHostByName (strHostName);
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine ("IP Address {0}: {1} ", i, addr[i].ToString ());
}
所属していません StackOverflow