예제 #1
0
        private static void SetHost(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            var configuration = (IConfiguration)options.ApplicationServices.GetService(typeof(IConfiguration));
            var host          = configuration.GetSection("RafHost").Get <Host>();

            foreach (var endpointKvp in host.Endpoints)
            {
                var endpointName = endpointKvp.Key;
                var endpoint     = endpointKvp.Value;
                if (!endpoint.IsEnabled)
                {
                    continue;
                }

                var address = IPAddress.Parse(endpoint.Address);
                options.Listen(address, endpoint.Port, opt =>
                {
                    if (endpoint.Certificate != null)
                    {
                        switch (endpoint.Certificate.Source)
                        {
                        case "File":
                            opt.UseHttps(endpoint.Certificate.Path, endpoint.Certificate.Password);
                            break;

                        default:
                            throw new NotImplementedException($"The source {endpoint.Certificate.Source} is not yet implemented");
                        }
                    }
                });

                options.UseSystemd();
            }
        }
예제 #2
0
        /// <summary>
        /// configure Kestrel to Host
        /// </summary>
        /// <param name="options"></param>
        internal static void SetHost(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            var configuration = (IConfiguration)options.ApplicationServices.GetService(typeof(IConfiguration));
            var host          = configuration.GetSection("RafHost").Get <Host>();  //依据Host类反序列化appsettings.json中指定节点

            foreach (var endpointKvp in host.Endpoints)
            {
                var endpointName = endpointKvp.Key;
                var endpoint     = endpointKvp.Value;            //获取appsettings.json的相关配置信息
                if (!endpoint.IsEnabled)
                {
                    continue;
                }

                var address = IPAddress.Parse(endpoint.Address);
                options.Listen(address, endpoint.Port, opt =>
                {
                    if (endpoint.Certificate != null)                    //证书不为空使用UserHttps
                    {
                        switch (endpoint.Certificate.Source)
                        {
                        case "File":
                            opt.UseHttps(endpoint.Certificate.Path, endpoint.Certificate.Password);
                            break;

                        default:
                            throw new NotImplementedException($"文件 {endpoint.Certificate.Source}还没有实现");
                        }
                        //opt.UseConnectionLogging();
                    }
                });

                options.UseSystemd();
            }
        }
예제 #3
0
        /// <summary>
        /// Get the conf file and set the passkey.
        /// </summary>
        private static void SetHost(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            var configuration = (IConfiguration)options.ApplicationServices.GetService(typeof(IConfiguration));

            options.Listen(IPAddress.Parse("0.0.0.0"), 5000, listenOptions =>
            {
                listenOptions.UseHttps("axelchef.pfx", configuration["ApplicationSettings:PassApi"]);
            });
        }
 private static void SetHost(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
 {
     //options.Listen(IPAddress.Any, 443, option =>
     //{
     //    //填入之前iis中生成的pfx文件路径和指定的密码 
     //    FileInfo fileInfo = new FileInfo("D:/iisSSL/ssl.pfx");
     //    if (fileInfo.Exists)
     //        option.UseHttps(fileInfo.FullName, "123456");
     //});
     options.Listen(IPAddress.Any, 8001);
 }
예제 #5
0
        private static void SetHost(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            var configuration = (IConfiguration)options.ApplicationServices.GetService(typeof(IConfiguration));
            var host          = configuration.GetSection("RafHost").Get <Host>();

            foreach (var endpointKvp in host.Endpoints)
            {
                var endpointName = endpointKvp.Key;
                var endpoint     = endpointKvp.Value;
                if (!endpoint.IsEnabled)
                {
                    continue;
                }

                var address = IPAddress.Parse(endpoint.Address);
                options.Listen(address, endpoint.Port, opt =>
                {
                    if (endpoint.Certificate != null)
                    {
                        switch (endpoint.Certificate.Source)
                        {
                        case "File":
                            opt.UseHttps(endpoint.Certificate.Path, endpoint.Certificate.Password);
                            break;

                        case "Store":
                            using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
                            {
                                store.Open(OpenFlags.ReadOnly);
                                var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", false);
                                if (certs.Count > 0)
                                {
                                    var certificate = certs[0];
                                    opt.UseHttps(certificate);
                                }
                            }
                            break;

                        default:
                            throw new NotImplementedException($"The source {endpoint.Certificate.Source} is not yet implemented");
                        }

                        //opt.UseConnectionLogging();
                    }
                });

                options.UseSystemd();   //?
            }
        }
예제 #6
0
        public static void ConfigureEndpoints(this Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            var configuration = options.ApplicationServices.GetService(typeof(IConfiguration));
            var environment   = (IWebHostEnvironment)options.ApplicationServices.GetService(typeof(IWebHostEnvironment));

            var endpoints = ((IConfiguration)configuration).GetSection("HttpServer:Endpoints")
                            .GetChildren()
                            .ToDictionary(section => section.Key, section =>
            {
                var endpoint = new EndpointConfiguration();
                section.Bind(endpoint);
                return(endpoint);
            });

            foreach (var endpoint in endpoints)
            {
                var config = endpoint.Value;
                var port   = config.Port ?? (config.Scheme == "https" ? 443 : 80);

                var ipAddresses = new List <System.Net.IPAddress>();
                if (config.Host == "localhost")
                {
                    ipAddresses.Add(System.Net.IPAddress.IPv6Loopback);
                    ipAddresses.Add(System.Net.IPAddress.Loopback);
                }
                else if (System.Net.IPAddress.TryParse(config.Host, out var address))
                {
                    ipAddresses.Add(address);
                }
                else
                {
                    ipAddresses.Add(System.Net.IPAddress.IPv6Any);
                }

                foreach (var address in ipAddresses)
                {
                    options.Listen(address, port,
                                   listenOptions =>
                    {
                        if (config.Scheme == "https")
                        {
                            var certificate = LoadCertificate(config, environment);
                            listenOptions.UseHttps(certificate);
                        }
                    });
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 应用配置
        /// </summary>
        /// <param name="path"></param>
        /// <param name="options"></param>
        public static void DeployConfig(string path, Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            // 当文件不存在时,执行初始化创建
            if (!System.IO.File.Exists(path))
            {
                using (dpz3.File.ConfFile file = new dpz3.File.ConfFile(path)) {
                    // 建立HTTP配置
                    var httpGroup = file["HTTP"];
                    httpGroup["Enable"] = "no";
                    httpGroup["Port"]   = "80";

                    // 建立HTTPS配置
                    var httpsGroup = file["HTTPS"];
                    httpsGroup["Enable"]       = "no";
                    httpsGroup["Port"]         = "443";
                    httpsGroup["Pfx.Path"]     = "/ssl/ssl.pfx";
                    httpsGroup["Pfx.Password"] = "******";

                    //文件保存
                    file.Save();
                }
            }

            // 读取配置
            using (dpz3.File.ConfFile file = new dpz3.File.ConfFile(path)) {
                // 读取HTTP配置
                var httpGroup = file["HTTP"];
                if (httpGroup["Enable"] == "yes")
                {
                    // 填入配置中的监听端口
                    options.Listen(IPAddress.Any, httpGroup["Port"].ToInteger());
                }

                // 读取HTTPS配置
                var httpsGroup = file["HTTPS"];
                if (httpsGroup["Enable"] == "yes")
                {
                    // 填入配置中的监听端口
                    options.Listen(IPAddress.Any, httpsGroup["Port"].ToInteger(), listenOptions => {
                        // 填入配置中的pfx文件路径和指定的密码       
                        listenOptions.UseHttps(httpsGroup["Pfx.Path"], httpsGroup["Pfx.Password"]);
                    });
                }
            }
        }
예제 #8
0
        /// <summary>
        /// 配置Kestrel
        /// </summary>
        /// <param name="options"></param>
        private static void SetHostUrl(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
        {
            //依据Host类反序列化appsettings.json中指定节点
            var hostUrl = ConfigurationJson.HostUrl;

            foreach (var endpointKvp in hostUrl.Endpoints)
            {
                var endpointName = endpointKvp.Key;
                var endpoint     = endpointKvp.Value;//获取appsettings.json的相关配置信息
                if (!endpoint.IsEnabled)
                {
                    continue;
                }

                var address = System.Net.IPAddress.Parse(endpoint.Address);
                options.Listen(address, endpoint.Port, opt =>
                {
                    if (endpoint.Certificate != null)//证书不为空使用UserHttps
                    {
                        if (endpoint.Certificate.Source != "File" || File.Exists(endpoint.Certificate.Path))
                        {
                            switch (endpoint.Certificate.Source)
                            {
                            case "File":
                                opt.UseHttps(endpoint.Certificate.Path, endpoint.Certificate.Password);
                                break;

                            default:
                                throw new NotImplementedException($"文件 {endpoint.Certificate.Source}还没有实现");
                            }
                            //opt.UseConnectionLogging();
                        }
                    }
                });

                options.UseSystemd();
            }
        }
예제 #9
0
 public static Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions UseSystemd(this Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
 {
     throw null;
 }
예제 #10
0
 public static Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions UseSystemd(this Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options, System.Action <Microsoft.AspNetCore.Server.Kestrel.Core.ListenOptions> configure)
 {
     throw null;
 }
 private static void ConfigureKestrel(WebHostBuilderContext builderContext, Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
 {
     options.Configure(builderContext.Configuration.GetSection("Kestrel"));
 }
예제 #12
0
 private static void configureOptions(Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options)
 {
     options.Limits.MaxConcurrentConnections         = null;
     options.Limits.MaxConcurrentUpgradedConnections = null;
 }