public ActionResult Check(DomainModel d) { UriBuilder uriBuilder; string domain = d.Domain; if (domain.StartsWith("http") == false) { d.Domain = "http://" + domain; } try { uriBuilder = new UriBuilder(d.Domain); } catch (UriFormatException) { ModelState.AddModelError("", ""); return View("Index"); } string uri = uriBuilder.Uri.ToString(); if (!Uri.IsWellFormedUriString(uri, UriKind.Absolute)) return RedirectToAction("Index"); var tenantDetail = CheckWebService(d); if (tenantDetail == null) { ModelState.AddModelError("", ""); return View("Index"); } // There's got to be a better way tenantDetail.HomePage = uri; Session.Add("tenantKey", tenantDetail); return View("UserSignIn"); }
private TenantDetailModel CheckWebService(DomainModel domainModel) { TenantDetailModel tenantDetailModel = null; Uri uri; string domain = domainModel.Domain; if (domain.StartsWith("http") == false) { domain = "http://" + domain; } try { uri = new Uri(domainModel.Domain); } catch (UriFormatException) { return null; } string url = string.Format("api/v1.0/Authentication/GetTenantDetail?communityUrl={0}", Server.UrlEncode(uri.ToString())); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://api.connectedcommunity.org/"); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); // List all products. HttpResponseMessage response = client.GetAsync(url).Result; // Blocking call! if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var tenantDetails = response.Content.ReadAsAsync<IEnumerable<TenantDetailModel>>().Result; foreach (var tenantDetail in tenantDetails) { tenantDetailModel = tenantDetail; } } else { } return tenantDetailModel; }