.net core系列(一)
用Vs 创建.NET Core web项目
首先介绍Main方法入口,0个引用说明是被框架调用

其中CreateHostBuilder方法如下:

其中 Startup类如下: Configure和ConfigureServices都是0个引用

以上标红的序号是他们的执行顺序。
private readonly HostingEnvironment _hostingEnvironment;
private readonly List<Action<WebHostBuilderContext, IServiceCollection>> _configureServicesDelegates;
private IConfiguration _config;
private WebHostOptions _options;
private WebHostBuilderContext _context;
private bool _webHostBuilt;
private List<Action<WebHostBuilderContext, IConfigurationBuilder>> _configureAppConfigurationBuilderDelegates;
public WebHostBuilder()//默认构造函数
{
_hostingEnvironment = new HostingEnvironment();
_configureServicesDelegates = new List<Action<WebHostBuilderContext, IServiceCollection>>();
_configureAppConfigurationBuilderDelegates = new List<Action<WebHostBuilderContext, IConfigurationBuilder>>();
_config = new ConfigurationBuilder().AddEnvironmentVariables("ASPNETCORE_").Build();
if (string.IsNullOrEmpty(GetSetting(WebHostDefaults.EnvironmentKey)))
{
UseSetting(WebHostDefaults.EnvironmentKey, Environment.GetEnvironmentVariable("Hosting:Environment") ?? Environment.GetEnvironmentVariable("ASPNET_ENV"));
}
if (string.IsNullOrEmpty(GetSetting(WebHostDefaults.ServerUrlsKey)))
{
UseSetting(WebHostDefaults.ServerUrlsKey, Environment.GetEnvironmentVariable("ASPNETCORE_SERVER.URLS"));
}
_context = new WebHostBuilderContext
{
Configuration = _config
}//
通过构造函数依赖注入方式
View Code2.UseConfiguration
传的控制台命令args就在这里执行
View Code3.UseKestrel
配置Kestrel服务器
View Code4.ConfigureAppConfiguration
View Code5.ConfigureLogging
配置日志
View Code6.ConfigureServices
View Code
View Code- Build()-构建
- Run()-构启动
View Code

因此显示以上信息

双击项目

AspNetCoreHostingModel配置了托管模式。InProcess指定进程内,OutProcess指定进程外
1.当AspNetCoreHostingModel设置InProcess进程内托管,启动IIS,任务管理器这时候有IIS Worker Process,网页服务器显示IIS
2.当AspNetCoreHostingModel设置InProcess进程内托管,启动项目,任务管理器这时候没有IIS Worker Process,网页服务器显示IIS
3.当AspNetCoreHostingModel设置OutProcess进程外托管,启动IIS,任务管理器这时候还是有IIS Worker Process,网页服务器显示Kestrel
4.当AspNetCoreHostingModel设置OutProcess进程外托管,启动项目,任务管理器没有IIS Worker Process,网页服务器显示Kestrel
这是怎么回事,怎么进程内外都会启动IIS Worker Process,进程内外到底有什么区别
原因分析:蓝色字体第1、3点进程内外的IIS服务都会启动,不过启动的作用确实不一样的
1.进程内启动IIS是当作服务器
2.进程外也启动IIS,是Kestrel配合IIS,将IIS当作反向代理服务器使用,不是作为整个项目的应用服务器了
以前是请求通过IIS监听,通过IIS托管代码响应直接完成
ASP.NET Core不同的是 靠ASP.NET Core Module把HTTP请求转发
IIS这个时候等同于Nginx反向代理,本身不再处理了
ASP.NET Core内置Kestrel服务器等价于IIS--Webserver
浙公网安备 33010602011771号