千家信息网

ASP.NET Core 1.0如何部署HTTPS

发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章给大家分享的是有关ASP.NET Core 1.0如何部署HTTPS的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。最近要做一个项目,正逢ASP.Net Core 1
千家信息网最后更新 2026年10月31日ASP.NET Core 1.0如何部署HTTPS

这篇文章给大家分享的是有关ASP.NET Core 1.0如何部署HTTPS的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

最近要做一个项目,正逢ASP.Net Core 1.0版本的正式发布。由于现代互联网的安全要求,HTTPS加密通讯已成主流,所以就有了这个方案。
本方案启发于一个旧版的解决方案:
ASP.NET Core 1.0 部署 HTTPS (.NET Framework 4.5.1)
http://www.cnblogs.com/qin-nz/p/aspnetcore-using-https-on-dnx451.html?utm_source=tuicool&utm_medium=referral
在反复搜索官方文档并反复尝试以后得出以下解决方案
在project.json 中,添加引用 Microsoft.AspNetCore.Server.Kestrel.Https

{ "dependencies": { //跨平台引用 //"Microsoft.NETCore.App": { // "version": "1.0.0", // "type": "platform" //}, "Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Razor.Tools": {  "version": "1.0.0-preview2-final",  "type": "build" }, "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.0", "Microsoft.AspNetCore.StaticFiles": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0" }, "tools": { "BundlerMinifier.Core": "2.0.238", "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }, "frameworks": { //跨平台引用 //"netcoreapp1.0": { // "imports": [ // "dotnet5.6", // "portable-net45+win8" // ] //} //Windows平台通用化引用 "net452": {} }, "buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true }, "runtimeOptions": { "configProperties": {  "System.GC.Server": true } }, "publishOptions": { "include": [  "wwwroot",  "Views",  "Areas/**/Views",  "appsettings.json",  "web.config" ], "exclude": [  "wwwroot/lib" ] }, "scripts": { "prepublish": [ "bower install", "dotnet bundle" ], "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] }}

在Program.cs中,增加HTTPS访问端口绑定

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Hosting;namespace Demo{ public class Program {  public static void Main(string[] args)  {   var host = new WebHostBuilder()    .UseKestrel()    .UseUrls("http://*", "https://*")    .UseContentRoot(Directory.GetCurrentDirectory())    .UseIISIntegration()    .UseStartup()    .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(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?}");   });   //https://docs.asp.net/en/latest/security/cors.html?highlight=https   app.UseCors(builder =>builder.WithOrigins("https://*").AllowAnyHeader());   app.Run(run =>   {    return run.Response.WriteAsync("Test");   });  } }}

感谢各位的阅读!关于"ASP.NET Core 1.0如何部署HTTPS"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

方案 内容 更多 篇文章 解决方案 不错 实用 安全 主流 互联网 官方 密码 平台 文件 文档 文章 版本 看吧 知识 端口 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 互联网佳科技有限公司 互联网科技有限公司图片 互联网 卓越科技 互联网科技媒体 互联网科技创新企业排名 农村开互联网科技讲堂 互联网科技有哪些公司 受益于互联网科技的高速发展 互联网公司科技股 河南猎农互联网科技有限公司 花神(南京)互联网科技有限公司 链环科技传统企业怎么转型互联网 互联网保险科技创业 工业互联网等科技实现智能化赋能 中天科技中国工业互联网 张召忠谈中国互联网科技 2021世界互联网领先科技成果发布 伍佰万互联网科技是干嘛的 恒生科技互联网指数十大成分股 互联网科技企业文化 智网互联网科技 苏州大垚互联网科技 互联网高科技企业 互联网科技生活的内容 茂名市互联网科技产业园 互联网校园科技培训 互联网科技有哪些公司 四川慕妮娅互联网科技有限公司 广州富喜互联网络科技 安徽零酒互联网科技有限公司
0