[英]how to use ssl certificates with gRPC and ASP Net Core 3.0?
[英]Problem with configuring ssl certificates in asp .net core API
我有以下證書證書
我想將我的 asp .net 核心 web API 配置為使用這些證書以使用 Z5E056Z1500A1C4BADE7 重定向。 我正在使用 Kestrel 進行應用程序設置。
{
"Kestrel": {
"EndPoints": {
"Https": {
"Url": "https://jj.com:5002"
}
}
}
}
我在閱讀一些在線帖子時嘗試自己做,但沒有結果。 這是我在 Startup.cs 文件中的配置方法。
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerManager logger)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "General API");
c.SupportedSubmitMethods();
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}");
});
}
這是我的 Program.cs 文件內容:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.Configure<KestrelServerOptions>(
context.Configuration.GetSection("Kestrel"));
}).ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseSetting("https_port", "443");
webBuilder.ConfigureKestrel(o =>
{
o.ConfigureHttpsDefaults(o =>
o.ClientCertificateMode =
ClientCertificateMode.RequireCertificate);
});
}).UseWindowsService();
}
任何幫助都感激不盡 !
如果我正確理解您的問題,您只想在紅隼上有 https。 您可以做的是在 appsetting.json 上添加以下設置
"HTTPS_PORT": "5151", "Kestrel": { "EndpointDefaults": { "Protocols": "Http1" }, "Certificates": { "Default": { "Path": "server_cert.pfx", "Password": "password" } } },
對於這一行o.ClientCertificateMode = ClientCertificateMode.RequireCertificate);
僅當您想使用客戶端證書時才使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.