feat(infra): implement ClientContext for IP and UserAgent from IHttpContextAccessor
This commit is contained in:
20
src/api/SIGCM2.Infrastructure/Http/ClientContext.cs
Normal file
20
src/api/SIGCM2.Infrastructure/Http/ClientContext.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using SIGCM2.Application.Abstractions;
|
||||||
|
|
||||||
|
namespace SIGCM2.Infrastructure.Http;
|
||||||
|
|
||||||
|
public sealed class ClientContext : IClientContext
|
||||||
|
{
|
||||||
|
private readonly IHttpContextAccessor _accessor;
|
||||||
|
|
||||||
|
public ClientContext(IHttpContextAccessor accessor)
|
||||||
|
{
|
||||||
|
_accessor = accessor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Ip =>
|
||||||
|
_accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "0.0.0.0";
|
||||||
|
|
||||||
|
public string? UserAgent =>
|
||||||
|
_accessor.HttpContext?.Request?.Headers.UserAgent.ToString();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user