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 学习笔记 宿主的更多相关文章

  1. DotNETCore 学习笔记 WebApi

    API Description Request body Response body GET /api/todo Get all to-do items None Array of to-do ite ...

  2. DotNETCore 学习笔记 MVC视图

    Razor Syntax Reference Implicit Razor expressions <p>@DateTime.Now</p> <p>@DateTim ...

  3. DotNETCore 学习笔记 依赖注入和多环境

    Dependency Injection ------------------------------------------------------------------------ ASP.NE ...

  4. DotNETCore 学习笔记 配置

    Configuration var builder = new ConfigurationBuilder(); builder.AddInMemoryCollection(); var config ...

  5. DotNETCore 学习笔记 日志

    Logging --------------------------------------------------------------------------------------- Impl ...

  6. DotNETCore 学习笔记 全球化和本地化

    Globalization and localization ********************************************************************* ...

  7. DotNETCore 学习笔记 异常处理

    Error Handling public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseIISP ...

  8. DotNETCore 学习笔记 路由

    Route ------------------------------------------constraint------------------------------------------ ...

  9. DotNETCore 学习笔记 Startup、中间件、静态文件

    Application Startup Startup Constructor - IHostingEnvironment - ILoggerFactory ConfigureServices - I ...

随机推荐

  1. es6严格模式需要注意的地方

    1.块级函数 "use strict"; if (true) { function f() { } // 语法错误 } es5中严格模式下禁止声明块级函数,而在es6的严格模式中可 ...

  2. 【多校联合】(HDU6043)KazaQ's Socks

    [多校联合](HDU6043)KazaQ's Socks 一条纯粹的水题,记录下只是因为自己错的太多而已. 原因在于对数据的细节的把握不佳. 原题 KazaQ's Socks Time Limit: ...

  3. 第二十篇 sys模块

    修改环境变量 import sys sys.path.append() 但是,这种修复方式只是临时修改 如果要永久修改,就要电脑里配置环境变量. sys.argv:命令行参数List,第一个元素是程序 ...

  4. Android基本组件

    ①Activity和View负责与用户交互 ②Service通常位于后台,拥有独立的生命周期,为其他组件提供后台服务和监控其他组件运行状态 ③BroadcastReceiver广播消息接收器,类似事件 ...

  5. C++ XML文件解析

    使用tinyxml2库,git地址https://github.com/leethomason/tinyxml2 只需要使用tinyxml2.h tinyxml2.cpp即可,同时需要using na ...

  6. KMP板子+Trie板子

    KMP算法是一个字符串匹配算法,最直白的用法就是在一个长度为n的字符串T中查找另一个长度为m字符串P的匹配(总之就是用于文本中进行单个字符串的匹配). 对于这个问题,暴力算法是很好做的,直接对于T的每 ...

  7. css制作环形文本

    css制作环形文本 在项目开发中,我们可能会遇到环形文本的需求,这个时候,怎样在代码以通俗易懂的前提下实现我们需要的效果呢?可能你会想到用一个一个的span元素计算出旋转的角度然后拼接起来,这个方案不 ...

  8. 团队项目-第十次scrum 会议

    时间:11.6 时长:20分钟 地点:主235教室走廊 工作情况 团队成员 已完成任务 待完成任务 解小锐 完成多种招聘方式的逻辑编写 陈鑫 实现游戏的存档功能 李金奇 添加多种招聘方式等功能 王辰昱 ...

  9. shell 中的expect 用法

    expect一般用于实现用脚本来自动远程登录,对远程机器执行相关操作 测试机上的expect目录一般在/usr/bin/expect路径 下面是从网上查询的用法总结: 1. expect中的判断语句: ...

  10. c++单例模式代码分析

    单例模式就是一个C++语法精华浓缩的一个体现,有句老话:麻雀虽小五脏俱全!来形容单例非常贴切! 下面的代码分析了如果自己malloc并且memcpy一个单例指针会带来很大危害并如何防止这种情况发生. ...