C
C#5mo ago
Ares

[ASP.NET CORE MVC] help with docker

So im trying to containerize my app with docker. I was able to get it working locally. but here is the problem: throughout my client side code where I fetch data from my api, I have hard coded the IIS Express url (https://localhost:44378/), and that is different than dockers URL(https://localhost:8080/). so whenever I launch my app with IIS Express instead of docker, all the fetches fail cause im pointing to the wrong port (also theres thing thing where https wont work but http will but ill worry about that later).
No description
1 Reply
Ares
Ares5mo ago
So the problem is that, if I want to run my app with IIS express again, I have to first change the client fetches to point to the IIS express url 44378 instead of the docker url 8080, and then after that I have to change the host in the connection string from db to localhost. Here is some of what I am talking about:

//home view with client javascript
$('#pagination-container').pagination({
dataSource: polls,
pageSize: 5,
pageRange: 1,
callback: function (data, pagination) {

const baseURL = "https://localhost:44378/" **should be https://localhost:8080/** for docker
const currentUrl = window.location.href

var dataContainer = $('#data-container');
.....stuff
}
})

//home view with client javascript
$('#pagination-container').pagination({
dataSource: polls,
pageSize: 5,
pageRange: 1,
callback: function (data, pagination) {

const baseURL = "https://localhost:44378/" **should be https://localhost:8080/** for docker
const currentUrl = window.location.href

var dataContainer = $('#data-container');
.....stuff
}
})
and then in my appsettings.json, where I have my connection string, I have to change the host from localhost to db:
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"GoogleKeys": {
"ClientId": "<clientid>",
"ClientSecret": "<clientsecret>"
},
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=realtime_poll;User Id=<userid>;Password=<password>SSL Mode=Disable;" **for IIS express, host should be localhost not db**
}
}
appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"GoogleKeys": {
"ClientId": "<clientid>",
"ClientSecret": "<clientsecret>"
},
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=realtime_poll;User Id=<userid>;Password=<password>SSL Mode=Disable;" **for IIS express, host should be localhost not db**
}
}
ive also attached my docker window to show what it looks like I feel like I have to tell which environment i am in but i still dont understand how it works in .net. can anyone help me please? thanks im not sure why i am trying to get iis to work now that i think about it but can anyone give me some advice about this nvm