// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Hosting.Server.Features; namespace Microsoft.AspNetCore.Hosting { public static class IWebHostPortExtensions { public static int GetPort(this IWebHost host) { return host.GetPorts().First(); } public static IEnumerable GetPorts(this IWebHost host) { return host.GetUris() .Select(u => u.Port); } public static IEnumerable GetUris(this IWebHost host) { return host.ServerFeatures.Get().Addresses .Select(a => new Uri(a)); } } }