本文整理汇总了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!");
});
}
示例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));
}
示例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();
}
示例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");
});
}
示例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");
});
}