美文网首页
为dotnet应用指定启动的端口

为dotnet应用指定启动的端口

作者: 黑山老雕 | 来源:发表于2022-01-18 17:48 被阅读0次

默认的dotnet webapp启动的端口是5000和5001,有5种方式可以自定义
5 ways to set the URLs for an ASP.NET Core app (andrewlock.net)

用代码

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
                webBuilder.UseUrls("http://localhost:5003", "https://localhost:5004");
            });
}

我喜欢参数的用法:

dotnet run --urls "http://localhost:5100;https://localhost:5101"
在linux下,可以直接在调用的可执行文件后加这个参数也可以 ./dotnet6test.Server --urls "http://localhost:5100;https://localhost:5101" 也可以

还有环境变量:

You can set environment variables in the usual way based on your environment. For example, using the command line:

setx ASPNETCORE_URLS "http://localhost:5001"
using powershell

$Env: ASPNETCORE_URLS = "http://localhost:5001"
or using bash:

export ASPNETCORE_URLS="http://localhost:5001;https://localhost:5002"

官方文档也可以参考一下这个:Configure endpoints for the ASP.NET Core Kestrel web server | Microsoft Docs

相关文章

  • 为dotnet应用指定启动的端口

    默认的dotnet webapp启动的端口是5000和5001,有5种方式可以自定义5 ways to set t...

  • Docker RabbitMQ

    下载镜像: 启动: 说明:-d 后台运行容器;--name 指定容器名;-p 指定服务运行的端口(5672:应用访...

  • nodejs修改文件后如何自动刷新

    推荐一个工具:nodemon 使用方法: 全局安装: 启动应用: 启动时指定端口: 开启debug模式:

  • docker 若干命令速记

    启动: 重启: 停止为 stop; 运行容器: 后台运行加参数 -d指定端口加参数 -p 开放端口:容器端口查看运...

  • Redis基础操作

    启动关闭 启动redis:redis-server默认端口6379,指定端口启动:redis-server --p...

  • 2018-03-06

    一、Windows下启动单个appium服务 需要启动多个appium服务,那必须为每个服务指定端口。 启动app...

  • windows服务器部署springboot应用包方式

    一、使用命令方式: 启动 停止1、先查看应用对应的端口进程 pid 是多少 2、强制杀死指定端口进程 二、使用批处...

  • Linux服务器对外开放端口

    有时候我们配置指定端口启动nginx服务器之后,浏览器无法访问指定端口,我们以Nginx为例: 首先检查nignx...

  • Redis常用命令

    启动Redis(默认端口号:6379) redis-server 启动Redis(指定端口号) redis-ser...

  • Redis命令和使用技巧

    基础命令 server: 启动server:redis-server 指定启动端口:redis-server --...

网友评论

      本文标题:为dotnet应用指定启动的端口

      本文链接:https://www.haomeiwen.com/subject/sfokhrtx.html