Base solution for your next web application
Open Closed

Audit Logs Not Capturing client IP address #9084


User avatar
0
suruat created

I have my api deployed to an Azure Appplication service. The audit table is working just fine but it is not capturing ClientIpAddress it always shows the same IP. Does anyone know how I can fix this?


6 Answer(s)
  • User Avatar
    0
    suruat created

    Does anyone have any idea about this?

  • User Avatar
    0
    aaron created
    Support Team

    172.16.1.1 is a private IP address. ​ You can configure it as a known proxy in app.UseForwardedHeaders(...) before app.UseAuthentication(). ​

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
    {
        ...
    ​
        var forwardedHeadersOptions = new ForwardedHeadersOptions                                // Add this
        {                                                                                        // Add this
            ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto // Add this
        };                                                                                       // Add this
        forwardedHeadersOptions.KnownProxies.Add(IPAddress.Parse("::ffff:172.16.1.1"));          // Add this
        app.UseForwardedHeaders(forwardedHeadersOptions);                                        // Add this
    ​
        app.UseAuthentication();
        
        ...
    }
    

    ​ Microsoft docs: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1

  • User Avatar
    0
    suruat created

    Sorry I wasnt clear. Im more interesting in capturing the actual public client IP address from the incoming reqesting. Currently that oa not happening. Im only getting the known IP. How can I do this?

  • User Avatar
    0
    aaron created
    Support Team

    I just told you exactly how and even provided a code sample that you can copy and paste directly into your ASP .NET Zero solution.

  • User Avatar
    0
    suruat created

    Oh Sorry!

    Trying this now.

  • User Avatar
    0
    suruat created

    Thanks @aaron, That seemed to have worked for me.