当前位置: 首页>>代码示例>>C#>>正文


C# IApplicationBuilder.UseKestrelHttps方法代码示例

本文整理汇总了C#中IApplicationBuilder.UseKestrelHttps方法的典型用法代码示例。如果您正苦于以下问题:C# IApplicationBuilder.UseKestrelHttps方法的具体用法?C# IApplicationBuilder.UseKestrelHttps怎么用?C# IApplicationBuilder.UseKestrelHttps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IApplicationBuilder的用法示例。


在下文中一共展示了IApplicationBuilder.UseKestrelHttps方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            //app.UseIISPlatformHandler();

            RemoteCertificateValidationCallback validationCallback = (sender, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.ServerCertificateValidationCallback += validationCallback;

            var connectionFilterOptions =
                new HttpsConnectionFilterOptions
                {
                    ServerCertificate = GetCertificateFromStore(),
                    ClientCertificateMode = ClientCertificateMode.RequireCertificate,
                    ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true
                };

            app.UseKestrelHttps(connectionFilterOptions);


            app.UseStaticFiles();

            app.UseMvc();

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
开发者ID:Rosiv,项目名称:KestrelWebApi,代码行数:28,代码来源:Startup.cs

示例2: ConfigureSSL

        /// <summary>
        /// Configures Kestrel to use HTTPS with the provided certificate path and file
        /// </summary>
        /// <param name="app">The <see cref="IApplicationBuilder"/> instance of the application</param>
        /// <param name="certPath">The file system path to the certificate file</param>
        /// <param name="password">The password of the certificate</param>
        public static void ConfigureSSL(IApplicationBuilder app, string certPath, string password)
        {
            if (string.IsNullOrEmpty(certPath))
            {
                throw new ArgumentException("The provided certificate path is invalid.");
            }

            app.UseKestrelHttps(new X509Certificate2(certPath, password));
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:15,代码来源:WebServerConfig.cs

示例3: Configure

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            var certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2("MyCertificate.pfx", "CertPass");
            app.UseKestrelHttps(certificate);

            app.UseIISPlatformHandler();

            app.UseStaticFiles();

            app.UseMvc();
        }
开发者ID:herecydev,项目名称:KestrelHTTPS,代码行数:15,代码来源:Startup.cs

示例4: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env)
        {
            var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
            //ksi.ThreadCount = 4;
            ksi.NoDelay = true;

            loggerFactory.AddConsole(LogLevel.Trace);

            var testCertPath = Path.Combine(
                env.ApplicationBasePath,
                @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx");

            if (File.Exists(testCertPath))
            {
                app.UseKestrelHttps(new X509Certificate2(testCertPath, "testPassword"));
            }
            else
            {
                Console.WriteLine("Could not find certificate at '{0}'. HTTPS is not enabled.", testCertPath);
            }

            app.UseKestrelConnectionLogging();

            app.Run(async context =>
            {
                Console.WriteLine("{0} {1}{2}{3}",
                    context.Request.Method,
                    context.Request.PathBase,
                    context.Request.Path,
                    context.Request.QueryString);
                Console.WriteLine($"Method: {context.Request.Method}");
                Console.WriteLine($"PathBase: {context.Request.PathBase}");
                Console.WriteLine($"Path: {context.Request.Path}");
                Console.WriteLine($"QueryString: {context.Request.QueryString}");

                var connectionFeature = context.Connection;
                Console.WriteLine($"Peer: {connectionFeature.RemoteIpAddress?.ToString()} {connectionFeature.RemotePort}");
                Console.WriteLine($"Sock: {connectionFeature.LocalIpAddress?.ToString()} {connectionFeature.LocalPort}");
                Console.WriteLine($"IsLocal: {connectionFeature.IsLocal}");

                context.Response.ContentLength = 11;
                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello world");
            });
        }
开发者ID:leloulight,项目名称:KestrelHttpServer,代码行数:45,代码来源:Startup.cs

示例5: Configure

        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IApplicationEnvironment env)
        {
            var ksi = app.ServerFeatures.Get<IKestrelServerInformation>();
            //ksi.ThreadCount = 4;
            ksi.NoDelay = true;

            loggerFactory.MinimumLevel = LogLevel.Debug;

            loggerFactory.AddConsole(LogLevel.Debug);

#if DNX451
            var testCertPath = Path.Combine(
                env.ApplicationBasePath,
                @"../../test/Microsoft.AspNet.Server.KestrelTests/TestResources/testCert.pfx");

            if (File.Exists(testCertPath))
            {
                app.UseKestrelHttps(new X509Certificate2(testCertPath, "testPassword"));
            }
            else
            {
                Console.WriteLine("Could not find certificate at '{0}'. HTTPS is not enabled.", testCertPath);
            }
#endif

            app.Run(async context =>
            {
                Console.WriteLine("{0} {1}{2}{3}",
                    context.Request.Method,
                    context.Request.PathBase,
                    context.Request.Path,
                    context.Request.QueryString);

                context.Response.ContentLength = 11;
                context.Response.ContentType = "text/plain";
                await context.Response.WriteAsync("Hello world");
            });
        }
开发者ID:Starcounter,项目名称:KestrelHttpServer,代码行数:38,代码来源:Startup.cs


注:本文中的IApplicationBuilder.UseKestrelHttps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。