当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net core自定义端口

asp.net core自定义端口

2018年08月23日  | 移动技术网IT编程  | 我要评论

春春配小四,css教程,吓死你爽子

asp.net core 自定义端口

官方文档

  • aspnet内库源码:
  • dotnet系统内库源码:

自定义端口访问

  • webhost增加useurls。 例:webhost.useurls(":5001",":5002");
  • 配置文件 hosting.json。例:

    通过查看webhost源码我们得知,启动后会先读取相关配置参数,

internal class webhost:iwebhost
{
    private static readonly string deprecatedserverurlskey = "server.urls";
    //...
    private void ensureserver()
    {
        if (server == null)
        {
            //...
            if (addresses != null && !addresses.isreadonly && addresses.count == 0)
            {
            var urls = _config[webhostdefaults.serverurlskey] ?? _config[deprecatedserverurlskey];                  
            }
        }
    }
}
public static class webhostdefaults{
    public static readonly string serverurlskey = "urls";
    //...
}
{"server.urls": "http://localhost:5003;http://localhost:5004"}
 public class program
 {
    public static void main(string[] args)
    {
        var config = new configurationbuilder()
            .setbasepath(directory.getcurrentdirectory())
            .addjsonfile("hosting.json", true)
            .build();

        buildwebhost(args, config).run();
            //buildwebhost(args).run();
    }

    public static iwebhost buildwebhost(string[] args, iconfiguration config) =>
        webhost.createdefaultbuilder(args)
            .usekestrel()
            //  .useurls("http://*:5001", "http://*:5002")
            .useconfiguration(config)
            .usestartup<startup>()
            .build();
    }
  • 配置环境变量。设置aspnetcore_urls、aspnet_env、aspnetcore_server.urls的值。

web服务器

  • kestrel(默认)
  • http.sys(在使用 iis 的反向代理配置中不起作用)
  • 自定义服务器

    >

    托管和部署

  • linux

    • centos7.2
  • windows

    • iis

    • windows服务

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网