ASP. 4000 NET Core 2.0系列学习笔记-应用程序启动
2018-02-26 22:42
841 查看
ASP.NET Core应用是一个在Main方法中创建的一个Web服务器的控制台应用程序。默认如下:
builder具有定义Web服务器(如:Kestrel)和指定启动类(如:UseStartup<Startup>)的方法。using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationMVC
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run(); //Run()启动IWebHost
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args) //设置默认依赖注入
.UseKestrel() //设置Web server为Kestrel
.UseContentRoot(Directory.GetCurrentDirectory()) //指定Webhost使用的contentroot(内容根目录),比如Views。默认为当前应用程序根目录。
.UseIISIntegration() //使用IISIntegration 中间件
.UseStartup<Startup>() //指定启动类
.Build(); //IWebHostBuilder负责创建IWebHost
}
}在上面的代码中,Web服务器Kestrel被启用(也可以指定其他Web服务器)。WebHostBuilder提供了一些可选方法,其中包括寄宿在IIS和IIS Express中的UseIISIntegration和用于指定根目录内容的UseContentRoot。Buile()和Run()方法构建了用于宿主应用程序的IWebHost,然后启动他来监听传入的HTTP请求。
using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; namespace NETCoreAPI { public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); //Run() 启动IWebHost } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) //设置默认依赖注入 .UseStartup<Startup>() //指定启动类:Startup .Build(); //IwebHostBuilder负责创建IWebHost } }Main方法调用遵循builder模式的WebHostBuilder,用于创建一个Web应用程序宿主。
builder具有定义Web服务器(如:Kestrel)和指定启动类(如:UseStartup<Startup>)的方法。using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace WebApplicationMVC
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run(); //Run()启动IWebHost
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args) //设置默认依赖注入
.UseKestrel() //设置Web server为Kestrel
.UseContentRoot(Directory.GetCurrentDirectory()) //指定Webhost使用的contentroot(内容根目录),比如Views。默认为当前应用程序根目录。
.UseIISIntegration() //使用IISIntegration 中间件
.UseStartup<Startup>() //指定启动类
.Build(); //IWebHostBuilder负责创建IWebHost
}
}在上面的代码中,Web服务器Kestrel被启用(也可以指定其他Web服务器)。WebHostBuilder提供了一些可选方法,其中包括寄宿在IIS和IIS Express中的UseIISIntegration和用于指定根目录内容的UseContentRoot。Buile()和Run()方法构建了用于宿主应用程序的IWebHost,然后启动他来监听传入的HTTP请求。
相关文章推荐
- ASP.NET Core 2.0系列学习笔记-启动类Startup
- ASP.NET Core 2.0系列学习笔记-应用程序修改默认端口支持外网IP访问
- ASP.NET 2.0高级编程学习笔记-第3章 应用程序和页面框架
- ASP.NET Core 2.0系列学习笔记-Middleware中间件
- ASP.NET Core 2.0系列学习笔记-ADO.NET-MSSQLServerHelper
- ASP.NET Core 2.0系列学习笔记-配置文件
- ASP.NET Core 2.0系列学习笔记-DI依赖注入
- ASP.NET Core 2.0系列学习笔记-NLog日志配置文件
- ASP.NET Core 2.0系列学习笔记-ORM框架之Dapper
- ASP.NET 3.5核心编程学习笔记:针对AJAX应用程序的WCF服务
- [学习笔记]Asp.net(C#)菜鸟进级系列之流程控制
- android性能优化学习笔记(加快应用程序启动速度:)
- NET2.0系列介绍(一).NET 2.0 中Web 应用程序主题的切换 ASP.NET 2.0 中Web 应用程序主题的切换 (ZZ)
- ASP.NET 2.0 状态管理 学习笔记(一)
- [ASP.NET学习笔记之三十]ASP.NET 2.0的代码隐藏和编译模型
- Asp.net 2.0 - Web Parts学习笔记
- ASP.NET MVC 3 学习笔记系列之Music Store(2)
- 关于asp.net 2.0 入门学习之“GlobalResources与Callback问题”的笔记
- VS2010与.NET4系列 7.自动启动ASP.NET应用程序
- 从0开始学习ASP.NET(2.0为例)系列——04C#/.NET FrameWork/ASP.NET相关基础知识介绍