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();
    }
  • 相关阅读:
    北京Uber优步司机奖励政策(12月9日)
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(12月9日)
    北京Uber优步司机奖励政策(12月8日)
    js中的json对象和字符串之间的转化
    fiddler Android下https抓包全攻略
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(12月7日)
    Android手机 Fildder真机抓包
    Android系统手机端抓包方法
    百度地图API示例之添加/删除工具条、比例尺控件
    百度地图API示例之设置级别setZoom与禁止拖拽disableDragging
  • 原文地址:https://www.cnblogs.com/ziranquliu/p/5872233.html
Copyright © 2011-2022 走看看