mirror of https://github.com/abpframework/abp.git
8 changed files with 16 additions and 66 deletions
@ -1,6 +0,0 @@ |
|||
namespace Volo.Abp.AspNetCore.ClientIpAddress; |
|||
|
|||
public interface IClientIpAddressProvider |
|||
{ |
|||
string? ClientIpAddress { get; } |
|||
} |
|||
@ -1,6 +0,0 @@ |
|||
namespace Volo.Abp.AspNetCore.ClientIpAddress; |
|||
|
|||
public class NullClientIpAddressProvider : IClientIpAddressProvider |
|||
{ |
|||
public string? ClientIpAddress => null; |
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
using System; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Microsoft.Extensions.Logging; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.ClientIpAddress; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class HttpContextClientIpAddressProvider : IClientIpAddressProvider, ITransientDependency |
|||
{ |
|||
protected ILogger<HttpContextClientIpAddressProvider> Logger { get; } |
|||
protected IHttpContextAccessor HttpContextAccessor { get; } |
|||
|
|||
public HttpContextClientIpAddressProvider( |
|||
ILogger<HttpContextClientIpAddressProvider> logger, |
|||
IHttpContextAccessor httpContextAccessor) |
|||
{ |
|||
Logger = logger; |
|||
HttpContextAccessor = httpContextAccessor; |
|||
} |
|||
|
|||
public string? ClientIpAddress => GetClientIpAddress(); |
|||
|
|||
protected virtual string? GetClientIpAddress() |
|||
{ |
|||
try |
|||
{ |
|||
return HttpContextAccessor.HttpContext?.Connection?.RemoteIpAddress?.ToString(); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Logger.LogException(ex, LogLevel.Warning); |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue