C# 如何使用“在本地主机上运行我的.Net web应用”;https";而不是",;http「;在Mac Os上
我现在的问题是,在上运行我的应用程序时,我总是遇到以下错误https://localhost:5000:C# 如何使用“在本地主机上运行我的.Net web应用”;https";而不是",;http「;在Mac Os上,c#,asp.net,asp.net-core,ssl,https,C#,Asp.net,Asp.net Core,Ssl,Https,我现在的问题是,在上运行我的应用程序时,我总是遇到以下错误https://localhost:5000: This site can’t provide a secure connection. localhost sent an invalid response. ERR_SSL_PROTOCOL_ERROR 我所做的是: 添加app.UseHsts(但这仅用于生产环境,不用于开发) 添加app.UseHttpsRedirection() 运行dotnet dev certs https-
This site can’t provide a secure connection.
localhost sent an invalid response.
ERR_SSL_PROTOCOL_ERROR
我所做的是:
app.UseHsts
(但这仅用于生产环境,不用于开发)app.UseHttpsRedirection()
dotnet dev certs https--trust
(如果我再次运行它,我会得到一个有效的https证书已经存在
)Startup.cs
code
public void ConfigureServices(IServiceCollection services)
{
services.ConfigureNonBreakingSameSiteCookies();
// services.AddHttpsRedirection(options => {
// options.HttpsPort = 5000;
// });
services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "AzureAdB2C")
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { Configuration["VivobodyApi:Scope"] })
.AddInMemoryTokenCaches();
services.AddControllersWithViews()
.AddMicrosoftIdentityUI();
services.AddRazorPages();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
//services.AddSingleton<ResultsService>();
services.AddHttpClient<IVivobodyApiService, VivobodyApiService>(configureClient =>
{
configureClient.BaseAddress = new Uri(Configuration.GetSection("VivobodyApi:Url").Value);
})
.AddPolicyHandler(GetRetryPolicy(services))
.AddPolicyHandler(GetCircuitBreakerPolicy(services));
services.AddHttpContextAccessor();
services.AddTransient<IIdentityService, IdentityService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
public void配置服务(IServiceCollection服务)
{
services.ConfigureNonBreakingSameSiteCookies();
//services.AddHttpsRedirection(选项=>{
//options.HttpsPort=5000;
// });
services.AddMicrosoftIdentityWebAppAuthentication(配置,“AzureAdB2C”)
.EnableTokenAcquisitionTollDownstreamAPI(新字符串[]{Configuration[“VivobodyApi:Scope”]})
.AddInMemoryTokenCaches();
services.AddControllersWithViews()
.AddMicrosoftIdentityUI();
services.AddRazorPages();
services.AddServerSideBlazor().AddMicrosoftIdentityConsentHandler();
//services.AddSingleton();
services.AddHttpClient(configureClient=>
{
configureClient.BaseAddress=新Uri(Configuration.GetSection(“VivobodyApi:Url”).Value);
})
.AddPolicyHandler(GetRetryPolicy(服务))
.AddPolicyHandler(GetCircuitBreakerPolicy(服务));
AddHttpContextAccessor();
services.AddTransient();
}
//此方法由运行时调用。使用此方法配置HTTP请求管道。
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(“/Error”);
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(端点=>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage(“/_主机”);
});
}