如何将ASP.NET Core 1.0应用程序成功部署并启用HTTPS连接?

2026-03-31 04:201阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计433个文字,预计阅读时间需要2分钟。

最近要做一个项目,需要使用ASP.Net Core 1.0版本正式发布。考虑到现代互联网的安全要求,项目已采用HTTPS加密通信,符合主流趋势。此方案基于一个旧版解决方案的升级:ASP.NET Core 1.0。

最近要做一个项目,正逢ASP.Net Core 1.0版本的正式发布。由于现代互联网的安全要求,HTTPS加密通讯已成主流,所以就有了这个方案。
本方案启发于一个旧版的解决方案:
ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)
www.cnblogs.com/qin-nz/p/aspnetcore-using-*", "*") .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } } }

在 Startup.cs 文件中,启用HTTPS访问并配置证书路径及密码

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.IO; using Microsoft.AspNetCore.Http; namespace Demo { public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.Configure<Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions>(option => { option.UseHttps(Path.Combine(new DirectoryInfo(Directory.GetCurrentDirectory()).FullName, "cret.pfx"), "pw"); }); } // 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(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=App}/{action=Index}/{id?}"); }); //docs.asp.net/en/latest/security/cors.html?highlight=*").AllowAnyHeader()); app.Run(run => { return run.Response.WriteAsync("Test"); }); } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

本文共计433个文字,预计阅读时间需要2分钟。

最近要做一个项目,需要使用ASP.Net Core 1.0版本正式发布。考虑到现代互联网的安全要求,项目已采用HTTPS加密通信,符合主流趋势。此方案基于一个旧版解决方案的升级:ASP.NET Core 1.0。

最近要做一个项目,正逢ASP.Net Core 1.0版本的正式发布。由于现代互联网的安全要求,HTTPS加密通讯已成主流,所以就有了这个方案。
本方案启发于一个旧版的解决方案:
ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)
www.cnblogs.com/qin-nz/p/aspnetcore-using-*", "*") .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } } }

在 Startup.cs 文件中,启用HTTPS访问并配置证书路径及密码

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System.IO; using Microsoft.AspNetCore.Http; namespace Demo { public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); services.Configure<Microsoft.AspNetCore.Server.Kestrel.KestrelServerOptions>(option => { option.UseHttps(Path.Combine(new DirectoryInfo(Directory.GetCurrentDirectory()).FullName, "cret.pfx"), "pw"); }); } // 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(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=App}/{action=Index}/{id?}"); }); //docs.asp.net/en/latest/security/cors.html?highlight=*").AllowAnyHeader()); app.Run(run => { return run.Response.WriteAsync("Test"); }); } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。