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. Java Web前后端分离的思考与实践

    第一节 Java Web开发方式的变化 Web开发虽然是我们常说的B/S模式,其实本质上也是一种特殊的C/S模式,只不过C和S的选择余地相对要窄了不少,而且更标准化.不论是采用什么浏览器和后端框架,W ...

  2. SSH公钥认证(码云)

    开发者向码云版本库写入最常用到的协议是 SSH 协议,因为 SSH 协议使用公钥认证,可以实现无口令访问,而若使用 HTTPS 协议每次身份认证时都需要提供口令.使用 SSH 公钥认证,就涉及到公钥的 ...

  3. [PocketFlow]解决TensorFLow在COCO数据集上训练挂起无输出的bug

    1. 引言 因项目要求,需要在PocketFlow中添加一套PeleeNet-SSD和COCO的API,具体为在datasets文件夹下添加coco_dataset.py, 在nets下添加pelee ...

  4. winform timer时间间隔小于执行时间

    如果SetTimer的时间间隔为t,其响应事件OnTimer代码执行一遍的时间为T,且T>t.这样,一次未执行完毕,下一次定时到,这时候程序会如何执行? 可能的情况:1.丢弃还未执行的代码,开始 ...

  5. 山科SDUST OJ Problem J :连分数

    Problem J: 连分数 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2723  Solved: 801[Submit][Status][Web B ...

  6. 微信公众号开发java框架:wx4j(MenuUtils篇)

    wx4j-MenuUtils使用 函数说明:发送http请求到微信服务器,完成菜单创建 参数:构造菜单对象 返回值:微信响应的json字符串 public static String createMe ...

  7. Android问题:could not install *smartsocket* listener;Address already in use

     今天启动genymotion后,发现没有ip地址,运行项目时报错:     可见,没有连接到模拟器,无法运行,而先前说过没有ip,自然而然连接不上,   解决放法:将资源管理器打开,将adb全部退出 ...

  8. 201621123033 《Java程序设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread 1.1 BallR ...

  9. PE文件格式介绍

    Useful Tools: 1. WDK安装目录下搜下depends.exe,这个工具可以查看.exe文件依赖的.dll,以及用到的dll中的api. 2.PE文件格式分析器: 有很多的PE格式分析器 ...

  10. 【bzoj1412】[ZJOI2009]狼和羊的故事 网络流最小割

    题目描述 “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! Orez的羊狼圈 ...