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. Virtual Host on Apache(Apache上建立虚拟主机)

    0. Introduction Usually, we want to build two or more websites on a web server, but we have only one ...

  2. springmvc基础篇—掌握三种控制器

    上一篇文章中我们讲过了处理器的映射,接下来我们来一起学习下springmvc的控制器吧. 首先咱们先创建一个咱们用来测试的实体(model)类: package cn.cfs.springmvc.do ...

  3. Leetcode代码补全——二叉树

    在刷leetcode的过程中发现,在原网页输入答案是不需要自己构筑树和链表的,虽然便于直接思考算法,但是久而久之类似过于依赖编辑器,反而不知道如何创建树和链表,因此总结了该网页省略的部分,以其中题为例 ...

  4. Unity和Lua交互

    用lua就表示项目用到了热更新,通常每次热更新都会从服务器获取最新的lua脚本放到Android/ios设备的本地目录下,但是lua应该放到哪个目录下呢,这里就先说说lua里面的路径问题 1.不可以放 ...

  5. Java 实现一个带提醒的定时器

    定时闹钟预览版EXE下载链接:https://files.cnblogs.com/files/rekent/ReadytoRelax_jar.zip 功能说明: 实现了一个休息提醒器,用户首先设定一个 ...

  6. Python中运算符"=="和"is"的差别分析

    前言 在讲is和==这两种运算符区别之前,首先要知道Python中对象包含的三个基本要素,分别是:id(身份标识).python type()(数据类型)和value(值).is和==都是对对象进行比 ...

  7. 轻量级权限管理系统——MVC基础

    Microsoft Web 开发平台

  8. lintcode-137-克隆图

    137-克隆图 克隆一张无向图,图中的每个节点包含一个 label 和一个列表 neighbors. 数据中如何表示一个无向图?http://www.lintcode.com/help/graph/ ...

  9. 对于response.setContentType(MIME)的解释

    response.setContentType(MIME)的作用是使客户端浏览器,区分不同种类的数据,并根据不同的MIME调用浏览器内不同的程序嵌入模块来处理相应的数据.例如web浏览器就是通过MIM ...

  10. LeetCode -- Tiangle

    Question: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to ...