C
C#3w ago
Whiteboy

✅ Connect WebApp to API ??

So i made 2 projects for my solution ASP.NET Core WebApp 6.0, and WebApi And when i try to connect from webapp to api all i get is "SocketException: No connection could be made because the target machine actively refused it." Im using IIS Express to run webapp which ports should i use? now i have in Webapp program.cs
builder.Services.AddHttpClient("WebApi", client =>
{
client.BaseAddress = new Uri("https://localhost:44390/api");
});
builder.Services.AddHttpClient("WebApi", client =>
{
client.BaseAddress = new Uri("https://localhost:44390/api");
});
and the lanuch settings of webapi
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8545",
"sslPort": 44390
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5095",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8545",
"sslPort": 44390
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5095",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
2 Replies
Pobiega
Pobiega3w ago
step 1: stop using IIS express use the https profile instead, this will just save you so much headache
Whiteboy
WhiteboyOP3w ago
okay, with https profile on port 5001 it works, thanks

Did you find this page helpful?