DotNETCore 学习笔记 宿主
Hosting
--------------------------------------------------------------------------
Setting up a Host :
using Microsoft.AspNetCore.Hosting;
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build(); host.Run();
}
} var host = new WebHostBuilder()
.UseKestrel()
.Configure(app =>
{
app.Run(async (context) => await context.Response.WriteAsync("Hi!"));
})
.Build(); host.Run();
--------------------------------------------------------------------------
Configuring a Host: new WebHostBuilder()
.UseSetting("applicationName", "MyApp") Host Configuration Values Application Name string
Key: applicationName. This configuration setting specifies the value that will be returned from IHostingEnvironment.ApplicationName.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Capture Startup Errors bool
Key: captureStartupErrors. Defaults to false. When false, errors during startup result in the host exiting. When true, the host will capture any exceptions from the Startup class and attempt to start the server. It will display an error page (generic, or detailed, based on the Detailed Errors setting, below) for every request. Set using the CaptureStartupErrors method. new WebHostBuilder()
.CaptureStartupErrors(true)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Content Root string
Key: contentRoot. Defaults to the folder where the application assembly resides (for Kestrel; IIS will use the web project root by default). This setting determines where ASP.NET Core will begin searching for content files, such as MVC Views. Also used as the base path for the Web Root setting. Set using the UseContentRoot method. Path must exist, or host will fail to start. new WebHostBuilder()
.UseContentRoot("c:\\mywebsite")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Detailed Errors bool
Key: detailedErrors. Defaults to false. When true (or when Environment is set to “Development”), the app will display details of startup exceptions, instead of just a generic error page. Set using UseSetting. new WebHostBuilder()
.UseSetting("detailedErrors", "true")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Environment string
Key: environment. Defaults to “Production”. May be set to any value. Framework-defined values include “Development”, “Staging”, and “Production”. Values are not case sensitive. See Working with Multiple Environments. Set using the UseEnvironment method. new WebHostBuilder()
.UseEnvironment("Development")
++++++++++++++++++++++++++++++++++++++++++++++++++
Server URLs string
new WebHostBuilder()
.UseUrls("http://*:5000;http://localhost:5001;https://hostname:5002")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Startup Assembly string
new WebHostBuilder()
.UseStartup("StartupAssemblyName")
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Web Root string
new WebHostBuilder()
.UseWebRoot("public") public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddJsonFile("hosting.json", optional: true)
.Build(); var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.Configure(app =>
{
app.Run(async (context) => await context.Response.WriteAsync("Hi!"));
})
.Build(); host.Run();
} +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
dotnet run --urls "http://*:5000"
var urls = new List<string>() {
"http://*:5000",
"http://localhost:5001"
};
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Start(urls.ToArray()); using (host)
{
Console.ReadLine();
}
DotNETCore 学习笔记 宿主的更多相关文章
- DotNETCore 学习笔记 WebApi
API Description Request body Response body GET /api/todo Get all to-do items None Array of to-do ite ...
- DotNETCore 学习笔记 MVC视图
Razor Syntax Reference Implicit Razor expressions <p>@DateTime.Now</p> <p>@DateTim ...
- DotNETCore 学习笔记 依赖注入和多环境
Dependency Injection ------------------------------------------------------------------------ ASP.NE ...
- DotNETCore 学习笔记 配置
Configuration var builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(); var config ...
- DotNETCore 学习笔记 日志
Logging --------------------------------------------------------------------------------------- Impl ...
- DotNETCore 学习笔记 全球化和本地化
Globalization and localization ********************************************************************* ...
- DotNETCore 学习笔记 异常处理
Error Handling public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseIISP ...
- DotNETCore 学习笔记 路由
Route ------------------------------------------constraint------------------------------------------ ...
- DotNETCore 学习笔记 Startup、中间件、静态文件
Application Startup Startup Constructor - IHostingEnvironment - ILoggerFactory ConfigureServices - I ...
随机推荐
- JavaScript序列化对象成URL格式
http://access911.net/fixhtm/72FABF1E15DCEAF3.htm?tt=
- MySQL☞insert value与values
最近公司事情太忙,作为以一挑十的测试,只能苦逼的累死累活的.好不容易临近上线,可以偷个懒写个文章. 简单的说说如何向表中插入数据: 1.向表中所有的列插入数据(插入多行数据): insert int ...
- 【page.json】配置说明
页面.json用来对本页面的窗口表现进行配置.它只能针对window配置,并且会覆盖 app.json 的 window 中相同的配置项. { /** * 以下是页面顶部导航栏设置 **/ " ...
- windowsserver2008 重新启动计算机命令
在windowsserver2008中,若要重新启动计算机,可以输入以下命令即可立即重启计算机shutdown -r -t 0命令意义:shutdown在英文中意为关掉,在计算机中即为关机参数意义:- ...
- Java开发JDBC连接数据库
Java开发JDBC连接数据库 创建一个以JDBC连接数据库的程序,包含6个步骤: JDBC五部曲1.加载驱动2.获得链接3.获取statement对象 4.执行SQL语句5.产生resultset对 ...
- html页面简单制作示例
内有表格布局,具体见 链接: https://pan.baidu.com/s/1V7IcxQ5M-iXVdlzuf8bo-A 密码: 8dp8
- Python如何进行中文注释
最近,由于实习工作的需要,开始接触Python,但是第一个大的脚本写下来之后,连中文注释都没办法加,很郁闷,遂在网上找解决办法,在Python 官网上看到这个页面:http://www.python. ...
- iOS-UIImageView播放动画
NSArray *gifArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"lanya1"],[UIImage imag ...
- Web-request内置对象在JSP编程中的应用
- lnmp1.4,400,500,错误
Thinkphp5或其他主流框架,入口文件未放在根目录下,比如Thinkphp5 入口文件放在/public/index.php vhost需要指向/public目录 一键安装包通常会报 open_b ...