Table of Contents

Class CurrentUserService

Namespace
NuvTools.Security.AspNetCore.Services
Assembly
NuvTools.Security.AspNetCore.dll

Provides information about the currently authenticated user and their connection details within an ASP.NET Core application.

public class CurrentUserService
Inheritance
CurrentUserService
Inherited Members

Remarks

This service is useful for retrieving user identity data (claims, identifiers, IP address, etc.) in controllers, Razor pages, or application services where dependency injection is available.

Constructors

CurrentUserService(IHttpContextAccessor)

Provides information about the currently authenticated user and their connection details within an ASP.NET Core application.

public CurrentUserService(IHttpContextAccessor httpContextAccessor)

Parameters

httpContextAccessor IHttpContextAccessor

Remarks

This service is useful for retrieving user identity data (claims, identifiers, IP address, etc.) in controllers, Razor pages, or application services where dependency injection is available.

Properties

Claims

Gets all claims of the current authenticated user as a collection of key/value pairs.

public IReadOnlyList<KeyValuePair<string, string>> Claims { get; }

Property Value

IReadOnlyList<KeyValuePair<string, string>>

Remarks

Each item represents a claim type and its corresponding value.

FullRemoteAddress

Gets a string combining the remote IP address and port number.

public string FullRemoteAddress { get; }

Property Value

string

Remarks

If the remote address is unavailable, this property returns an empty string.

NameIdentifier

Gets the unique identifier (NameIdentifier claim) of the current authenticated user.

public string? NameIdentifier { get; }

Property Value

string

Remarks

This typically corresponds to the sub claim in JWT-based authentication or the user ID in ASP.NET Identity.

RemoteIpAddress

Gets the remote IP address of the current HTTP request, if available.

public string? RemoteIpAddress { get; }

Property Value

string

RemotePort

Gets the remote port of the current HTTP request, if available.

public int? RemotePort { get; }

Property Value

int?