[..net core]4.入口,Main方法 及InProcess

通常控件台程序都有一个main方法,  

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

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }

.net core web app也有一个,因为它启动的时候就是一个控制台程序

在这个main方法中 配置了一些.net core web app的参数,然后启动它 ,为控制台程序根据之前讲过的AspNetCoreHostingModel创建了一个寄宿环境

这里他就成为一个.net core web app.

AspNetCoreHostingModel 之前有说过  可以设置成inProcess和outProcess

当设置成inprocess(托管于服务器)时, 比设置成outProcess具有更高的吞吐量能力

把startup.cs里的Configure方法里的打印hello word的代码 改变成 打印进程名称

  await context.Response.WriteAsync(Process.GetCurrentProcess().ProcessName);

ctrl + f5 运行起来的效果

这时我们知道 .net core web app在调试时使用是IIS作为web服务器,寄舍在iisexpress.exe进程中,可以从任务栏浏览或关掉它.

扫描二维码关注公众号,回复: 6941704 查看本文章

当我们使用命令行dotnet run

 看到的效果 

 这时我们知道, 当我们使用dotnet run 时, 他不再使用iis 托管,而是使用.net core的内置 web服务器 kerstrel 

kerstrel是 .net core web app 的跨平台内置web服务器

猜你喜欢

转载自www.cnblogs.com/nocanstillbb/p/11296074.html
今日推荐