Home > database >  C# .NET 7 Blazor WASM App and Server, can't change listening port 5000
C# .NET 7 Blazor WASM App and Server, can't change listening port 5000

Time:01-05

I have created my first Blazor application. The application has an API(Server), Client and a Shared Class Library.

When I publish the app to a local folder and then copy it to IIS it is working but the listening port for the API stays on http://localhost:5000. I am running the app on https://example.com so it won't be able to access http://localhost:5000 because of the mix in http and https.

Where can I change that port so that it can work on https://example.com?

CodePudding user response:

Modify the launchSettings.json file to specify the custom domain and port for your application. The launchSettings.json file is typically located in the Properties folder of your application.

To change the port, you will need to add a new element to the profiles object in the launchSettings.json file. The element should have a key that represents the name of your profile (e.g., "IIS Express" or "Local") and a value that is an object containing the port and protocol settings for the profile.

launchSettings.json file to change the port:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:5000",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "MyProfile": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://example.com",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

You can Specify the port for https://example.com

{
  "profiles": {
    "MyProfile": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://example.com:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Configure your web server to listen on the desired port and handle requests for the custom domain. The specific steps will depend on the web server you are using.
For example, if you are using IIS, you can follow these steps:

  • Open the IIS Manager and select the site that you want to configure.
  • Click the "Bindings" link in the "Actions" pane.
  • Click "Add" to add a new binding for the site.
  • In the "Add Site Binding" dialog, select "https" as the "Type" and enter the desired port (e.g., 5000) and domain (e.g., example.com).
  • Click "OK" to save the binding.

Make sure that the port you are using is open and not being blocked by a firewall or other security measures.

  • Related