asp.net core自定义端口
asp.net Core 自定义端口
官方文档
- aspnet内库源码: https://github.com/aspnet
- dotnet系统内库源码:https://github.com/dotnet
- asp.net core 官方文档
自定义端口访问
- webHost增加UseUrls。 例:WebHost.UseUrls("http://:5001","http://: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服务
asp.net core自定义端口的更多相关文章
- asp.net core 自定义认证方式--请求头认证
asp.net core 自定义认证方式--请求头认证 Intro 最近开始真正的实践了一些网关的东西,最近写几篇文章分享一下我的实践以及遇到的问题. 本文主要介绍网关后面的服务如何进行认证. 解决思 ...
- 如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容?
原文:如何在ASP.NET Core自定义中间件中读取Request.Body和Response.Body的内容? 文章名称: 如何在ASP.NET Core自定义中间件读取Request.Body和 ...
- asp.net core 自定义异常处理中间件
asp.net core 自定义异常处理中间件 Intro 在 asp.net core 中全局异常处理,有时候可能不能满足我们的需要,可能就需要自己自定义一个中间件处理了,最近遇到一个问题,有一些异 ...
- asp.net core 自定义 Policy 替换 AllowAnonymous 的行为
asp.net core 自定义 Policy 替换 AllowAnonymous 的行为 Intro 最近对我们的服务进行了改造,原本内部服务在内部可以匿名调用,现在增加了限制,通过 identit ...
- asp.net core 自定义基于 HttpContext 的 Serilog Enricher
asp.net core 自定义基于 HttpContext 的 Serilog Enricher Intro 通过 HttpContext 我们可以拿到很多有用的信息,比如 Path/QuerySt ...
- ASP.NET CORE 自定义视图组件(ViewComponent)注意事项
*红色字体为固定命名,蓝色为一般命名规则,黄色为ASP.NET CORE 默认查找文件名 概要:1.简单ViewComponent的用法 2.ViewComponent控制器返回值 3.注意事项 1 ...
- 解决 ASP.NET Core 自定义错误页面对 Middleware 异常无效的问题
我们基于 Razor Class Library 实现了自定义错误页面的公用类库(详见之前的随笔),但是在实际使用时发现如果在 middleware 中发生了异常,则不能显示自定义错误页面,而是返回默 ...
- asp.net core 自定义401和异常显示内容(JWT认证、Cookie Base认证失败显示内容)
asp.net core 2.0使用JWT认证园子里已经有挺多帖子了,但开发中发现认证未授权情况下返回的401状态码是没有任何信息的,业务中可能有需要返回一串错误的Json信息.在这里我分享一个自定义 ...
- Asp.Net Core 自定义设置Http缓存处理
一.使用中间件 拦截请求自定义输出文件 输出前自定义指定响应头 public class OuterImgMiddleware { public static string RootPath { ge ...
随机推荐
- [Swift]LeetCode169. 求众数 | Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- [Swift]LeetCode706. 设计哈希映射 | Design HashMap
Design a HashMap without using any built-in hash table libraries. To be specific, your design should ...
- [Swift]LeetCode813. 最大平均值和的分组 | Largest Sum of Averages
We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the su ...
- 白话说java gc垃圾回收
gc是java区别于其他好几门语言(c/c++)的一个代表功能(当然也有很多可以自动管理内存的语言,如所有的脚本语言,你根本不知道内存管理这回事)! 当然,之所以要把c/c++和java相比,是因为j ...
- Redis 设计与实现 (二)--数据库
typedef struct redisDb { dict *dict; /* The keyspace for this DB */ dict *expires; /* Timeout of key ...
- admui框架使用经验
刚开始接触admui框架时确实有些迷茫,不知道怎么使用,摸索了一段时间后才发现这个框架很简单!以下是我遇见的一些坑,总结一下啦! 1.使用框架第一步就是开启服务器,我给公司写项目时开启的是5000端口 ...
- ESXI开启snmp协议方法
公司用VMware做虚拟化,15+HPE 服务器做集群,现需要用zabbix监控其状态,于是想通过打开主机的snmp协议来采集数据,监控其状态,注意其数据是ESXI系统返回的. ssh登录到ESXI上 ...
- rabbitMQ linux安装
1,下载 erlang (http://www.rabbitmq.com/releases/erlang/) wget http://www.rabbitmq.com/releases/erlang/ ...
- redis 系列10 字符串对象
一. 字符串对象编码 Redis中字符串可以存储3种类型,分别是字节串(byte string).整数.浮点数.在上章节中讲到字符串对象的编码可以是int, raw,embstr. 如果一个字符串对象 ...
- 在.NET Core console application中使用User Secrets(用户机密)
微软很坑地只在Microsoft.NET.Sdk.Web中提供了VS项目右键菜单的"管理用户机密"/"Manage User Secrets"菜单项,在使用Mi ...