Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrei Revi 5 posts 95 karma points
    Feb 10, 2023 @ 13:29
    Andrei Revi
    0

    Umbraco Forms [@Remote_Addr]

    Hello! I am newbie and need help with Umbraco Forms. Using Magic String [@Remote_Addr] I get an IP encrypted by CloudFlare. How to get real IP?

  • Yakov Lebski 591 posts 2347 karma points
    Feb 10, 2023 @ 17:53
    Yakov Lebski
    100

    https://developers.cloudflare.com/fundamentals/get-started/reference/http-request-headers/

    try read CF-Connecting-IP or HTTPXFORWARDED_FOR headers

     public static string GetIpAddress(this IHttpContextAccessor accessor)
        {
            if (!string.IsNullOrEmpty(accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"]))
                return accessor.HttpContext.Request.Headers["CF-CONNECTING-IP"];
    
            var ipAddress = accessor.HttpContext.GetServerVariable("HTTP_X_FORWARDED_FOR");
    
            if (!string.IsNullOrEmpty(ipAddress))
            {
                var addresses = ipAddress.Split(',');
                if (addresses.Length != 0)
                    return addresses.Last();
            }
    
            return accessor.HttpContext.Connection.RemoteIpAddress.ToString();
        }
    
  • Andrei Revi 5 posts 95 karma points
    Feb 10, 2023 @ 18:23
    Andrei Revi
    0

    Thanks for the answer!

Please Sign in or register to post replies

Write your reply to:

Draft