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)
-
0
Does anyone have any idea about this?
-
0
172.16.1.1
is a private IP address.
You can configure it as a known proxy inapp.UseForwardedHeaders(...)
beforeapp.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 -
0
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?
-
0
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.
-
0
Oh Sorry!
Trying this now.
-
0
Thanks @aaron, That seemed to have worked for me.