اجبار به استفادهی از HTTPS در حین توسعهی برنامههای ASP.NET Core 2.1
نویسنده: وحید نصیری
تاریخ: ۱۳۹۷/۰۱/۰۳ ۱۱:۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001 Now listening on: http://localhost:5000
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection(); services.AddHttpsRedirection(options => options.HttpsPort = 5002);
services.AddHsts(options =>
{
options.MaxAge = TimeSpan.FromDays(100);
options.IncludeSubDomains = true;
options.Preload = true;
}); ASP.NET Core ------------ Successfully installed the ASP.NET Core HTTPS Development Certificate.
dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final dotnet dev-certs https --trust
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:4929",
"sslPort": 44313
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HTTPS_PORT": "44313"
}
},
"TestWebApp": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000"
}
}
}
}
System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found. To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'. For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
Secure Connection Failed An error occurred during a connection to localhost:5001. Certificate key usage inadequate for attempted operation. Error code: SEC_ERROR_INADEQUATE_KEY_USAGE
dotnet dev-certs https --clean dotnet dev-certs https --trust
dotnet install tool dotnet-dev-certs -g --version 2.1.0-preview1-final
dotnet tool install dotnet-dev-certs -g
dotnet dev-certs https --clean dotnet dev-certs https --trust
>dotnet --in Host (useful for support): Version: 2.2.7 Commit: b1e29ae826 .NET Core SDKs installed: No SDKs were found. .NET Core runtimes installed: Microsoft.AspNetCore.All 2.2.5 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.2.5 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.2.5 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
"C:\Program Files\Git\usr\bin\openssl.exe" genrsa -out private.key 2048 "C:\Program Files\Git\usr\bin\openssl.exe" req -new -x509 -key private.key -out publickey.cer -days 1398 "C:\Program Files\Git\usr\bin\openssl.exe" pkcs12 -export -out idp.pfx -inkey private.key -in publickey.cer