更新时间:2022-10-25 08:14:49
Request.ServerVariables [REMOTE_ADDR]。ToString();
Request.ServerVariables( REMOTE_ADDR)
或
Request.UserHostAddress
您可以使用Request.ServerVariables [REMOTE_ADDR]
或Request.ServerVariables [HTTP_X_FORWARDED_FOR]
。
见此功能:public static string GetIPAddress()
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
string sIPAddress = context.Request.ServerVariables [ HTTP_X_FORWARDED_FOR跨度>];
if ( string .IsNullOrEmpty(sIPAddress)){
return context.Request.ServerVariables [ REMOTE_ADDR];
} else {
string [] ipArray = sIPAddress.Split( new Char [] {' ,'}) ;
return ipArray [ 0 ];
}
}
- Amit
HI all can anyone help me out how to get the client ip address in asp.net web application
thank you in advanvce
Request.ServerVariables["REMOTE_ADDR"].ToString();
Request.ServerVariables("REMOTE_ADDR") or Request.UserHostAddress
You can get it usingRequest.ServerVariables["REMOTE_ADDR"]
orRequest.ServerVariables["HTTP_X_FORWARDED_FOR"]
.
See this function:public static string GetIPAddress() { System.Web.HttpContext context = System.Web.HttpContext.Current; string sIPAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(sIPAddress)) { return context.Request.ServerVariables["REMOTE_ADDR"]; } else { string[] ipArray = sIPAddress.Split(new Char[] { ',' }); return ipArray[0]; } }
--Amit