launchsettings with different port for API

204 Views Asked by At

My API Project settings:

  "profiles": {
"LGSafetyAPI": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "launchUrl": "swagger",
  "applicationUrl": "https://localhost:7295;http://localhost:5295",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
},
"IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "launchUrl": "swagger",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}

}

MVC Project settings are:

"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
  "applicationUrl": "http://localhost:52964",
  "sslPort": 44394
}

MVC project gives an ajax call to find API...but since the url is different it's trying to find

localhost:44394 instead of localhost:7295

how can I change these settings as per the environment?

I remember working with similar setup react project with .net api project..it worked seemlessly ..but somehow it looks hard here.

1

There are 1 best solutions below

1
Zhi Lv On

Check the JQuery Ajax request URL, try to use the fixed request URL, like this:

        $.ajax({
            type: "Get",
            url: "https://localhost:7295/APIController/ActionName", 
            success: function (response) {
                console.log(response); 

            },
            error: function (xhr, textStatus, errorThrown) {
                console.log('in error');
            }
        });