校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0)

ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0)

熱門標(biāo)簽:臨沂智能電話機(jī)器人加盟 400電話辦理怎么樣 蘇州如何辦理400電話 網(wǎng)絡(luò)電話外呼系統(tǒng)上海 聯(lián)通官網(wǎng)400電話辦理 西寧呼叫中心外呼系統(tǒng)線路商 百應(yīng)電話機(jī)器人外呼系統(tǒng) 外呼電話機(jī)器人成本 地圖標(biāo)注軟件免費(fèi)下載

最近要做一個項目,正逢ASP.Net Core 1.0版本的正式發(fā)布。由于現(xiàn)代互聯(lián)網(wǎng)的安全要求,HTTPS加密通訊已成主流,所以就有了這個方案。
本方案啟發(fā)于一個舊版的解決方案:
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=tuicoolutm_medium=referral
 在反復(fù)搜索官方文檔并反復(fù)嘗試以后得出以下解決方案
 在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()
    .UseStartupStartup>()
    .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.ConfigureMicrosoft.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?}");
   });

   //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");
   });

  }
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • win10下ASP.NET Core部署環(huán)境搭建步驟
  • 在IIS上部署ASP.NET Core項目的圖文方法
  • 如何在ASP.NET Core應(yīng)用程序運(yùn)行Vue并且部署在IIS上詳解
  • 詳解ASP.NET Core Docker部署
  • 詳解Asp.Net Core 發(fā)布和部署( MacOS + Linux + Nginx )
  • Asp.net Core 初探(發(fā)布和部署Linux)
  • Linux下部署.net core環(huán)境的步驟詳解
  • Centos7+Docker+Jenkins+ASP.NET Core 2.0自動化發(fā)布與部署的實現(xiàn)
  • .Net Core部署到CentOS的圖文教程
  • .net core部署到windows服務(wù)上的完整步驟

標(biāo)簽:臨夏 甘肅 清遠(yuǎn) 慶陽 海西 聊城 中衛(wèi)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0)》,本文關(guān)鍵詞  ASP.NET,Core,1.0,部署,HTTPS,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0)》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 竹溪县| 嘉义县| 金门县| 阳谷县| 建水县| 济源市| 托克逊县| 丘北县| 晋城| 长泰县| 抚宁县| 泸西县| 白城市| 河西区| 大关县| 吉安县| 苗栗县| 天峨县| 黎城县| 鹿邑县| 富宁县| 佛坪县| 吐鲁番市| 新田县| 西畴县| 宜良县| 文山县| 大名县| 子洲县| 六盘水市| 武鸣县| 永兴县| 冀州市| 清镇市| 乐东| 夏邑县| 河津市| 武鸣县| 邢台县| 慈利县| 伽师县|