zoukankan      html  css  js  c++  java
  • DotNet 学习笔记 Servers

    Servers
    
    ASP.NET Core ships with two different HTTP servers:
    
    •Microsoft.AspNetCore.Server.Kestrel (AKA Kestrel, cross-platform)
    •Microsoft.AspNetCore.Server.WebListener (AKA WebListener, Windows-only, preview)
    
    {
      "webroot": "wwwroot",
      "version": "1.0.0-*",
    
      "dependencies": {
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final"
      },
    
      "commands": {
        "run": "run server.urls=http://localhost:5003",
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000",
        "weblistener": "Microsoft.AspNet.Hosting --server WebListener --server.urls http://localhost:5004"
      },
    
      "frameworks": {
        "dnx451": { },
    
    
    using System;
    using System.Threading.Tasks;
    using Microsoft.AspNet.Hosting;
    using Microsoft.Extensions.Configuration;
    using Microsoft.AspNet.Builder;
    using Microsoft.Extensions.Logging;
    using Microsoft.AspNet.Server.Kestrel;
    
    namespace ServersDemo
    {
        /// <summary>
        /// This demonstrates how the application can be launched in a console application. 
        /// Executing the "dnx run" command in the application folder will run this app.
        /// </summary>
        public class Program
        {
            private readonly IServiceProvider _serviceProvider;
    
            public Program(IServiceProvider serviceProvider)
            {
                _serviceProvider = serviceProvider;
            }
    
            public Task<int> Main(string[] args)
            {
                //Add command line configuration source to read command line parameters.
                var builder = new ConfigurationBuilder();
                builder.AddCommandLine(args);
                var config = builder.Build();
    
                using (new WebHostBuilder(config)
                    .UseServer("Microsoft.AspNet.Server.Kestrel")
                    .Build()
                    .Start())
                {
                    Console.WriteLine("Started the server..");
                    Console.WriteLine("Press any key to stop the server");
                    Console.ReadLine();
                }
                return Task.FromResult(0);
            }
        }
    }
    ------------------------------------------------------------------------------
    Programmatic configuration
    
    public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime, ILoggerFactory loggerFactory)
    {
        var webListenerInfo = app.ServerFeatures.Get<WebListener>();
        if (webListenerInfo != null)
        {
            webListenerInfo.AuthenticationManager.AuthenticationSchemes =
                AuthenticationSchemes.AllowAnonymous;
        }
    
        var serverAddress = app.ServerFeatures.Get<IServerAddressesFeature>()?.Addresses.FirstOrDefault();
    
        app.Run(async (context) =>
        {
            var message = String.Format("Hello World from {0}",
                                    serverAddress);
            await context.Response.WriteAsync(message);
        });
    }
    
    "web": "Microsoft.AspNetCore.Hosting --server Microsoft.AspNetCore.Server.WebListener --server.urls http://localhost:5000"
  • 相关阅读:
    Django的templates(模板)
    Django的urls(路由)
    Markdown中实现折叠代码块
    图片上传2
    Comparator 排序
    Serializable 序列化为文件
    统计连续签到的方法
    Serializable 序列化为字符串 base64
    Serializable 序列化使用限制
    Serializable 剔除某些不想保存的字段 transient
  • 原文地址:https://www.cnblogs.com/ziranquliu/p/5884265.html
Copyright © 2011-2022 走看看