[C#] 纯文本查看 复制代码
string ip = string.Empty;
string X_Forwarded_For = Request.Headers["X-Forwarded-For"];
if (!string.IsNullOrWhiteSpace(X_Forwarded_For))
{
ip = X_Forwarded_For;
}
else
{
string CF_Connecting_IP = Request.Headers["CF-Connecting-IP"];
if (!string.IsNullOrWhiteSpace(CF_Connecting_IP))
{
ip = CF_Connecting_IP;
}
else
{
ip = Request.UserHostAddress;
}
}
[JavaScript] 纯文本查看 复制代码
<script>
$.cookie("mobile", 0, { domain: "jjoobb.cn" });
$.get("XXXX自己的网址", function (result) {
if (result) {
if(result.toString().length > 10 && result.toString().tolocaleLowerCase().indexOf("object")>0)
{
window.location.href = result;
}
}
});
</script>
[C#] 纯文本查看 复制代码
/// <summary>
/// IP操作帮助类
/// 编码人:苏飞
/// 编码时间:2015-05-18
/// </summary>
public class IPHelper
{
/// <summary>
/// 提取开启代理/cdn服务后的客户端真实IP
/// </summary>
/// <returns></returns>
public static string GetTrueIP()
{
string ip = string.Empty;
string X_Forwarded_For =HttpContext.Current.Request.Headers["X-Forwarded-For"];
if (!string.IsNullOrWhiteSpace(X_Forwarded_For))
{
ip = X_Forwarded_For;
}
else
{
string CF_Connecting_IP = HttpContext.Current.Request.Headers["CF-Connecting-IP"];
if (!string.IsNullOrWhiteSpace(CF_Connecting_IP))
{
ip = CF_Connecting_IP;
}
else
{
ip = HttpContext.Current.Request.UserHostAddress;
}
}
return ip;
}
}