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 ...
随机推荐
- c++ combination by next_permutation
#include <iostream> #include <algorithm> #include <vector> int main() { int n, r; ...
- Android Studio 使用小结
从去年(2013年5月)Google发布Android Studio 0.1.0版本,到如今已经一年多了,已经升级到0.8.6 Beta版 ,从刚开始大家报怨bug多,编译困难,到如今已经基本趋于稳定 ...
- 「日常训练」 Mike and Frog (CFR305D2C)
题意与分析 (Codeforces 548C) 我开始以为是一条数学题,死活不知道怎么做,无奈看题解,才知这是一条暴力,思维江化了- - 题意大概是这样的: 两个东西的初始高度分别为h1,h2&quo ...
- zabbix 2.2 调小监控值
zabbix_agent默认disk下小于0%告警 调小到5% 组态 > 模板 选择需要的模板的触发器 例如 Template OS Windows 选择触发器 - 探索规则 - 触发器类型 ...
- 【Linux运维】Centos7上借助ansible搭建LVS+Keepalived
安装ansible 安装ansible: [root@localhost ~]# /etc/hosts 192.168.19.129 web129.yanglt.com web129 192.168. ...
- python 动态函数调用及可变参数传入
定义类及方法 class ParameterFactory(object): ..... def fullLinkTag(self, fromDate, toDate, status, cate='全 ...
- java设计模式之模版方法模式以及在java中作用
模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑.不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的逻辑有 ...
- [leetcode-634-Find the Derangement of An Array]
In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no ...
- 大数运算——hdu1042N!
一.题目回顾 题目链接:N! Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! ...
- ubuntu 14.04 安装opencv 3.0 测试
安装opencv 前面步骤参考 http://my.oschina.net/u/1757926/blog/293976 主要修改测试代码 1. 先从sourceforge上下载OpenCV的源码 2. ...