-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Audit info parameters - WebAPI #467
Comments
That means we can not get IP address of the client. I don't know the exact reason for you situation. This is a warning, system works without logging IP address of the user. You may disable this log in log4net.config if you want. But it's better to find the reason why GetHostAddresses can not get IP address of the client. Do you have an idea? Maybe it's related to your server or client configurations. |
Server is located on Microsoft Azure. Maybe there is some restriction. On localhost, there is no problem. |
I've tested this on another server and everything worked fine. I suppose there is some issue on Microsoft Azure. So, I'm closing this issue. |
Would ask that this be reopened, since it is remains a problem when running on Azure. The calls to Dns.GetHostAddresses will throw SocketException when resolution fails or is unavailable, which causes this exception to fill logs with noise. I don't see why the resolution can't be wrapped in a try block to save the logs from these warnings, or at least provide a configuration to disable warnings if resolution fails? If not, how can this behavior be overridden effectively? |
OK, we will catch the exception. |
Thanks! I'm not sure whether this call has an associated timeout that might be in play, but would want to also make sure this is done in a non-blocking/async way. Do audited web service calls have to wait for the audit code to finish or is that asychronous? |
As I remember, auditing was sync. I will check it while implementing this. Thanks. |
I got the same problem on Azure. After a remote debugging session i can see that So maybe the solution is to take the httpContext.Request.UserHostAddress value by default ? Thanks |
I got the same issue on Azure too. All my audited services in AuditLogs table have nulls ClientIpAddress and ClientName. Is there any chance of setting as fallback ClientIpAddress the HttpContext.Request.UserHostAddress or maybe, as it is a string, something like "PossibleIP:214.55.0.2" to indicate that might be a proxy ip. |
I cached exceptions for Dns.GetHostAddresses call. New code is like that: protected virtual string GetClientIpAddress(HttpContext httpContext)
{
var clientIp = httpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ??
httpContext.Request.ServerVariables["REMOTE_ADDR"];
try
{
foreach (var hostAddress in Dns.GetHostAddresses(clientIp))
{
if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
{
return hostAddress.ToString();
}
}
foreach (var hostAddress in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (hostAddress.AddressFamily == AddressFamily.InterNetwork)
{
return hostAddress.ToString();
}
}
}
catch (Exception ex)
{
Logger.Debug(ex.ToString());
}
return clientIp;
} As you see, I did it virtual. So, you can create a new class inherits from WebAuditInfoProvider and override GetClientIpAddress to change code for your application. Then you can replace IAuditInfoProvider service with your own implementation (#983 (comment)). |
thanks @hikalkan this upgrade will help us a lot. Waiting for the nuget release ;) |
@hikalkan, thank you for adding this. Can you provide an example of how to override the class so that the app uses my new implementation? It appears my new class is not getting used by the DI container. |
Hi @automys, the following worked on me to replace the build in service
And in your preinitialize webmodule
|
Thanks @tamys, this works! |
Hi,
I have custom WebAPI on the remote server. On every request there is a warning in the log file.
WARN|Abp.Auditing.WebAuditInfoProvider|System.Net.Sockets.SocketException (0x80004005): No such host is known at System.Net.Dns.GetAddrInfo(String name) at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6) at System.Net.Dns.GetHostAddresses(String hostNameOrAddress) at Abp.Auditing.WebAuditInfoProvider.GetClientIpAddress(HttpContext httpContext) at Abp.Auditing.WebAuditInfoProvider.Fill(AuditInfo auditInfo)
What's the problem?
The text was updated successfully, but these errors were encountered: