- public static string IPAddress
- {
- get
- {
- HttpRequest request = HttpContext.Current.Request;
- string text;
- if (string.IsNullOrEmpty(request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
- {
- text = request.ServerVariables["REMOTE_ADDR"];
- }
- else
- {
- text = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
- }
- if (string.IsNullOrEmpty(text))
- {
- text = request.UserHostAddress;
- }
- return text;
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1907201614882.html
来源: http://www.codesnippet.cn/detail/1907201614882.html