您现在的位置是:网站首页> 编程资料编程资料
ASP.NET 获取客户端IP方法_实用技巧_
2023-05-24
354人已围观
简介 ASP.NET 获取客户端IP方法_实用技巧_
话不多说,请看代码:
string requestClientIpAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(requestClientIpAddress)) requestClientIpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; if (string.IsNullOrEmpty(requestClientIpAddress)) requestClientIpAddress = HttpContext.Current.Request.UserHostAddress;
经过测试 存在负载均衡的时候 ,HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] 取出的是真实的客户端 IP地址 ,而HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] 和 HttpContext.Current.Request.UserHostAddress 取出的是被分配的保留地址
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
相关内容
- ASP.NET MVC 导出Word报表_实用技巧_
- .NET中用ICSharpCode.TextEditor自定义代码折叠与高亮_实用技巧_
- SignalR发送页面跳转通知的方法_实用技巧_
- ASP.NET MVC 项目直接预览PDF文件_实用技巧_
- 基于ASP.NET Core数据保护生成验证token示例_实用技巧_
- ASP.NET MVC5 实现分页查询的示例代码_实用技巧_
- ASP.NET 定时器回调方法的重入_实用技巧_
- asp.net core mvc实现伪静态功能_实用技巧_
- Asp.net中Microsoft.Identity的IPasswordHasher加密的默认实现与运用_实用技巧_
- 剖析Asp.Net Web API路由系统---WebHost部署方式_实用技巧_
