I have to ASP.NET applications: one is a Web API and the other a MVC that makes requests to the first.
Everthing works in development (VS with IIS Express) but now I publish both applications to a production server and I can´t have access to the api using the MVC app.
I have CORS enabled on the API:
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
On the MVC app, my api base url is set to https://localhost:44351/ and then in the IIS I have this bindings (WEB Api site):
I can make requests to the API with postman but when I run the my MVC app, I can´t make requests (and again, I could make them in development).
Thank you.
EDIT
Controller code example (MVC):
try
{
var client = WebApiHttpClient.GetClient();
var response = await client.PostAsync("Token", content);
if (response.IsSuccessStatusCode)
{
TokenResponse tokenResponse =
await response.Content.ReadAsAsync<TokenResponse>();
WebApiHttpClient.storeToken(tokenResponse);
return RedirectToAction("Index", "Home");
}
else
{
return Content("response.StatusCode);
}
}
catch
{
return Content("Error");
}
My HttpClient implementation:
public const string WebApiBaseAddress = "https://localhost:44351/";
public static HttpClient GetClient()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(WebApiBaseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
return client;
}
EDIT 2
InnerException message:
the underlying connection was closed could not establish trust relationship for the ssl/tls