最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net core - How to set Blazor Web App UI to use static port? - Stack Overflow

programmeradmin3浏览0评论

In .Net 9, If you create a Blazor Web App, in development, the user interface always start on a dynamic port.

I'd like to always start on a statically defined port. I've updated launchSettings.json to do that for for https, I think...

{
  "$schema": ".json",
    "profiles": {
      "http": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "http://localhost:59301",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "https": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "https://localhost:59300",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      }
    }
  }

But it always chooses some random port every time it loads in development.

Is this a Kestrel issue? The AppHost sites always come up on the launchSettings URL & port set in that project.

I've verified that the 59300 port is not in use with netstat

netstat -ano | find "59300"

How can I force the user interface development site to always come up on a port like 59300 for https?

In .Net 9, If you create a Blazor Web App, in development, the user interface always start on a dynamic port.

I'd like to always start on a statically defined port. I've updated launchSettings.json to do that for for https, I think...

{
  "$schema": "https://json.schemastore./launchsettings.json",
    "profiles": {
      "http": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "http://localhost:59301",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "https": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
        "applicationUrl": "https://localhost:59300",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      }
    }
  }

But it always chooses some random port every time it loads in development.

Is this a Kestrel issue? The AppHost sites always come up on the launchSettings URL & port set in that project.

I've verified that the 59300 port is not in use with netstat

netstat -ano | find "59300"

How can I force the user interface development site to always come up on a port like 59300 for https?

Share Improve this question edited yesterday Zhi Lv 22k1 gold badge27 silver badges37 bronze badges asked 2 days ago Robert AchmannRobert Achmann 2,0453 gold badges45 silver badges72 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Your launchSettings.json content is correct. I created a new Blazor Web App project, replaced the launchSettings.json file with yours, and ran the application. It always uses https://localhost:59300. You can create a new application to verify it.

But it always chooses some random port every time it loads in development.

About this issue, I suggest you check the Program.cs content, have your ever change the port via the following method:

//config webhost
builder.WebHost.UseUrls("https://localhost:59305", "http://localhost:59306");

//or
//config kesrel
builder.WebHost.ConfigureKestrel(options =>
{
    options.ListenAnyIP(5001); // HTTP
    options.ListenAnyIP(5002, listenOptions => listenOptions.UseHttps()); // HTTPS
});

Besides, you can also verify the correct project and profile is selected.

  1. Right-click the Blazor project in VS and select Set as Startup Project.

  2. In Visual Studio, ensure the https profile is selected from the dropdown. If using the CLI, run: dotnet run --launch-profile "https"

Finally, you can try to delete bin and obj folders. Restart Visual Studio to clear cached settings and then rebuild the application.

发布评论

评论列表(0)

  1. 暂无评论