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 ...
随机推荐
- [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- [Swift]LeetCode283. 移动零 | Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...
- [Swift]LeetCode404. 左叶子之和 | Sum of Left Leaves
Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...
- [Swift]LeetCode606. 根据二叉树创建字符串 | Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preo ...
- kubernetes---docker-image
imagePullPolicy <String> Always : 总是从仓库下载 , 如果是image的tag是latest ,如果需要一直保持最新,则应设为Always ,从仓库下载 ...
- 【web.xml】项目从web.xml开始
前言 依自己目前的所闻所见,每个项目的WEB-INF下都会带有一个web.xml配置文件.当启动项目时,web容器(tomcat)会首先去读取web.xml中的内容,读取加载完成后才算完成了项目的启动 ...
- python连接Linux命令行
#!/usr/bin/python # -*- coding: utf-8 -*- '''https://www.ibm.com/developerworks/cn/linux/l-cn-pexpec ...
- Python内置函数(48)——ord
英文文档: ord(c) Given a string representing one Unicode character, return an integer representing the U ...
- java多线程(8)---阻塞队列
阻塞队列 再写阻塞列队之前,我写了一篇有关queue集合相关博客,也主要是为这篇做铺垫的. 网址:[java提高]---queue集合 在这篇博客中我们接触的队列都是非阻塞队列,比如Priority ...
- 解放双手—Cobbler批量自动化部署多版本系统
1 Cobbler 介绍 Cobbler 是一个 Linux 服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装.重装物理服务器和虚拟机,同时还可以管理 DHCP,DNS 等.Cobble ...