diff --git a/src/Commands/Base/PnPConnection.cs b/src/Commands/Base/PnPConnection.cs index 514b01d50..4e3082b6d 100644 --- a/src/Commands/Base/PnPConnection.cs +++ b/src/Commands/Base/PnPConnection.cs @@ -196,6 +196,11 @@ internal static PnPConnection CreateWithACSAppOnly(Uri url, string realm, string if (realm == null) { realm = GetRealmFromTargetUrl(url); + + if(realm == null) + { + throw new Exception($"Could not determine realm for the target site '{url}'. Please validate that a site exists at this URL."); + } } if (url.DnsSafeHost.Contains("spoppe.com")) @@ -772,7 +777,7 @@ internal static string GetRealmFromTargetUrl(Uri targetApplicationUri) client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", ""); var response = client.GetAsync(targetApplicationUri + "/_vti_bin/client.svc").GetAwaiter().GetResult(); - if (response == null) + if (response == null || response.StatusCode == System.Net.HttpStatusCode.NotFound) { return null; }