zoukankan      html  css  js  c++  java
  • 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();
    }
  • 相关阅读:
    linux 常用命令-编辑模式
    关于react虚拟DOM的研究
    oracle 分页的sql语句
    react+webpack+wepack-dev-server的环境中ant design图标离线的方法
    oracle 语句之对数据库的表名就行模糊查询,对查询结果进行遍历,依次获取每个表名结果中的每个字段(存储过程)
    eclipse 中使用git
    好东西要分享
    《梦断代码》阅读笔记二
    《梦断代码》阅读笔记一
    第二段冲刺进程4
  • 原文地址:https://www.cnblogs.com/ziranquliu/p/5872233.html
Copyright © 2011-2022 走看看