{"record":{"id":"d7deae24baf97515","repo":"TechnitiumSoftware/DnsServer","slug":"the-domain-name-domain-does-not-belong-to-the","errorCode":null,"errorMessage":"The domain name '<domain>' does not belong to the zone: <zoneName>","messagePattern":"The domain name '<domain>' does not belong to the zone: <zoneName>","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs","lineNumber":693,"sourceCode":"        internal static string GetParentZone(string domain)\n        {\n            int i = domain.IndexOf('.');\n            if (i > -1)\n                return domain.Substring(i + 1);\n\n            //dont return root zone\n            return null;\n        }\n\n        internal static bool DomainBelongsToZone(string zoneName, string domain)\n        {\n            return domain.Equals(zoneName, StringComparison.OrdinalIgnoreCase) || domain.EndsWith(\".\" + zoneName, StringComparison.OrdinalIgnoreCase) || (zoneName.Length == 0);\n        }\n\n        internal static void ValidateIfDomainBelongsToZone(string zoneName, string domain)\n        {\n            if (!DomainBelongsToZone(zoneName, domain))\n                throw new DnsServerException(\"The domain name '\" + domain + \"' does not belong to the zone: \" + zoneName);\n        }\n\n        #endregion\n\n        #region auth zone tree methods\n\n        private ApexZone CreateEmptyApexZone(AuthZoneInfo zoneInfo)\n        {\n            ApexZone apexZone;\n\n            switch (zoneInfo.Type)\n            {\n                case AuthZoneType.Primary:\n                    apexZone = new PrimaryZone(_dnsServer, zoneInfo);\n                    break;\n\n                case AuthZoneType.Secondary:\n                    apexZone = new SecondaryZone(_dnsServer, zoneInfo);","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/ZoneManagers/AuthZoneManager.cs#L675-L711","documentation":"Thrown by AuthZoneManager.ValidateIfDomainBelongsToZone when a domain name is neither equal to the zone name, nor a child of it (does not end with '.'+zoneName), and the zone is not the root zone (zoneName.Length == 0). It enforces that record operations target a domain actually inside the named zone, preventing cross-zone writes.","triggerScenarios":"Calling a record API (add/update/delete) with a domain that belongs to a different zone or is outside the zone's authority, after ValidateIfDomainBelongsToZone(zoneName, domain) is invoked internally.","commonSituations":"Trying to add 'www.other.com' into the 'example.com' zone; a missing/extra trailing label; a sub-domain delegation where the record belongs to the delegated child zone; caller passing the FQDN including a zone it does not own.","solutions":["Ensure the domain is the zone apex or a sub-domain of it (domain == zoneName or domain ends with '.' + zoneName).","Resolve the correct zone for the domain first (longest-suffix zone match) before issuing the record operation.","Strip an erroneous trailing root dot or extra labels from the domain before validation."],"exampleFix":"// before\nzoneManager.AddRecord(\"other.com\", \"www.other.com\", ...);\n\n// after\nif (!AuthZoneManager.DomainBelongsToZone(zoneName, domain))\n    throw new ArgumentException($\"{domain} not in zone {zoneName}\");\nzoneManager.AddRecord(zoneName, domain, ...);","handlingStrategy":"validation","validationCode":"void EnsureDomainInZone(string zoneName, string domain)\n{\n    if (!AuthZoneManager.DomainBelongsToZone(zoneName, domain))\n        throw new ArgumentException($\"'{domain}' is not in zone '{zoneName}'\");\n}\n// usage:\nEnsureDomainInZone(zoneName, domain);\nzoneManager.AddRecord(zoneName, domain, ...);","typeGuard":"static bool BelongsToZone(string zoneName, string domain) =>\n    AuthZoneManager.DomainBelongsToZone(zoneName, domain);","tryCatchPattern":null,"preventionTips":["Resolve the longest-suffix matching zone for a domain before record operations.","Call DomainBelongsToZone before ValidateIfDomainBelongsToZone to fail gracefully.","Normalize domain casing and trailing dots before zone-membership checks."],"tags":["dns","csharp","zone-management","validation","api-misuse","technitium"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}