---
title: "Normalize a Unicode domain in C#"
url: https://recursiveai.org/onecontact/cookbook/canonicalize-idn-domain/
description: "Normalize a Unicode domain name to ASCII in C# with OneContact. Get the Punycode host and keep all subdomains, not just the registrable domain."
version: "1.0.0"
---

# Normalize a Unicode domain in C#

**OneContact** is a free, open-source contact data library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies, no network access.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneContact) · [GitHub](https://github.com/recursive-ai-oss/onecontact-csharp) · [Docs](https://recursiveai.org/onecontact/docs/) · [Download example (.zip)](https://recursiveai.org/onecontact/cookbook/canonicalize-idn-domain/canonicalize-idn-domain.zip)

Get the ASCII host, including subdomains.

```shell
dotnet add package RecursiveAI.OneContact
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneContact;

var url = WebAddress.Parse(
    "www.Bücher.example");
Console.WriteLine(url.Host);
```

The ASCII host is:

```text
www.xn--bcher-kva.example
```

The `xn--` prefix marks a label encoded with Punycode.

Unzip [the example](https://recursiveai.org/onecontact/cookbook/canonicalize-idn-domain/canonicalize-idn-domain.zip), then `dotnet run`.

## Full program

```csharp
using RecursiveAI.OneContact;

var composed = WebAddress.Parse("www.Bücher.example");
var decomposed = WebAddress.Parse("www.Bu\u0308cher.example");
Console.WriteLine(composed.Host);
Console.WriteLine(decomposed.Host);
```

`dotnet run` prints:

```text
www.xn--bcher-kva.example
www.xn--bcher-kva.example
```

The first input uses `ü`; the second uses `u` followed by a combining diaeresis (`\u0308`). `Parse` throws `ContactParseException` if the web address can’t be parsed.

## Variations

Read the normalized host from a full HTTPS URL with a path:

```csharp
using RecursiveAI.OneContact;

var url = WebAddress.Parse(
    "https://faß.example/catalog");
Console.WriteLine(url.Host);
```

```text
xn--fa-hia.example
```

`WebAddress` doesn’t expose a Unicode host; for a domain in an email address, use `EmailAddress.UnicodeDomain` (with the same `using RecursiveAI.OneContact;`):

```csharp
Console.WriteLine(EmailAddress.Parse("info@xn--bcher-kva.example").UnicodeDomain);
```

```text
bücher.example
```

## Related recipes

- [Get the registrable domain from a URL in C#](https://recursiveai.org/onecontact/cookbook/get-domain-from-url/)
- [Parse a URL in C#](https://recursiveai.org/onecontact/cookbook/parse-url/)

## The short answer

Read `WebAddress.Host` to get the full normalized host. OneContact assumes `https` for a bare domain such as `www.Bücher.example`. It returns `www.xn--bcher-kva.example` as the host, without the scheme, port, or path. Use `Host`, not `RegistrableDomain`: the latter uses the Public Suffix List to look up the domain that can be registered, which can leave out subdomains such as `www`.

## What does “normalize Unicode” mean for a domain name?

Unicode can represent the same letter in more than one way. The two spellings of `ü` in the full program differ as strings but give the same host. Ordinary [Unicode normalization](https://learn.microsoft.com/en-us/dotnet/api/system.string.normalize?view=net-10.0) can put both spellings into the same Unicode form, but it does not turn a hostname into ASCII.

For web hosts, OneContact follows [Unicode UTS #46](https://recursiveai.org/onecontact/docs/idna/#processing): it maps characters, applies Unicode normalization, checks the labels between the dots, and encodes non-ASCII labels. The URL path isn’t part of this operation. `WebAddress` parses URLs rather than validating a domain-only form field, and does not check DNS. If your field must accept only domains, don’t infer that from parse success: the same API also accepts full URLs and IP addresses.

## What is Punycode in a domain name?

[Punycode](https://www.rfc-editor.org/rfc/rfc3492) is the encoding used for domain labels that contain non-ASCII characters. IDNA, short for Internationalized Domain Names in Applications, marks an encoded label with `xn--`. In `www.xn--bcher-kva.example`, only `bücher` had to be encoded; the ASCII labels `www` and `example` did not. The `faß` example also keeps `ß` in the encoded result rather than changing it to `ss`, because OneContact’s [web host processing](https://recursiveai.org/onecontact/docs/web/#canonical-form) uses non-transitional mapping.
