TechnitiumSoftware/DnsServer · error · DnsWebServiceException

No such user exists: {username}

Error message

No such user exists: {username}

What it means

Thrown by AuthManager.CreateSession (the username overload) when GetUser(username) returns null, i.e. the user store has no matching record. It is a DnsWebServiceException because it surfaces as a fault to the web service caller during login/token creation. The message echoes the offending username to make the mismatch obvious.

Source

Thrown at DnsServerCore/Auth/AuthManager.cs:1177

            if (type == UserSessionType.ClusterApiToken)
                throw new InvalidOperationException();

            UserSession session = new UserSession(type, tokenName, user, remoteAddress, userAgent);

            if (!_sessions.TryAdd(session.Token, session))
                throw new DnsWebServiceException("Error while creating session. Please try again.");

            user.LoggedInFrom(remoteAddress);

            return session;
        }

        public UserSession CreateSession(UserSessionType type, string tokenName, string username, IPAddress remoteAddress, string userAgent)
        {
            User user = GetUser(username);
            if (user is null)
                throw new DnsWebServiceException("No such user exists: " + username);

            return CreateSession(type, tokenName, user, remoteAddress, userAgent);
        }

        public UserSession CreateSession(UserSessionType type, string tokenName, User user, IPAddress remoteAddress, string userAgent)
        {
            if (user.Disabled)
                throw new DnsWebServiceException("User account is disabled. Please contact your administrator.");

            UserSession session = new UserSession(type, tokenName, user, remoteAddress, userAgent);

            if (!_sessions.TryAdd(session.Token, session))
                throw new DnsWebServiceException("Error while creating session. Please try again.");

            user.LoggedInFrom(remoteAddress);

            return session;
        }

View on GitHub (pinned to d0484b6c1e)

Solutions

  1. Confirm the username exists in the users store (case-insensitively, since names are lowercased) before requesting a session.
  2. Create the missing user account first, then retry CreateSession.
  3. Check whether the user was recently deleted/disabled by an admin and restore it if appropriate.

Example fix

// before
var session = authManager.CreateSession(type, tokenName, username, remoteAddress, userAgent);

// after
if (authManager.GetUser(username.ToLowerInvariant()) is null)
    return Error($"No such user exists: {username}");
var session = authManager.CreateSession(type, tokenName, username, remoteAddress, userAgent);
Defensive patterns

Strategy: validation

Validate before calling

// Resolve the user before requesting a session.
string normalized = username?.ToLowerInvariant()?.Trim();
if (string.IsNullOrEmpty(normalized))
    return BadRequest("Username required.");
if (authManager.GetUser(normalized) is null)
    return NotFound($"No such user exists: {username}");
// safe to create session now

Try / catch

// Only if you cannot pre-validate (e.g. caller has no GetUser access):
try { var session = authManager.CreateSession(type, tokenName, username, remoteAddress, userAgent); }
catch (DnsWebServiceException ex) when (ex.Message.StartsWith("No such user exists"))
{ return NotFound(ex.Message); }

Prevention

When it happens

Trigger: Calling CreateSession(type, tokenName, username, remoteAddress, userAgent) where 'username' does not resolve to an existing User. This is the path the username-based login / token-creation endpoint takes before it can build a UserSession.

Common situations: Wrong/typo'd username at login; the user was deleted between auth checks and session creation; case mismatch (note usernames are normalized with ToLowerInvariant elsewhere, so a differently-cased lookup can miss); a restored config that references a user that no longer exists.

Related errors


AI-assisted analysis of TechnitiumSoftware/DnsServer@d0484b6c1e (2026-08-13). Data as JSON: /api/errors/22c274e99425e540. Report an issue: GitHub.