一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0)

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

2020-01-21 14:25歐陽敏嵐VicBilibily ASP.NET教程

這篇文章主要為大家詳細(xì)介紹了ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0),感興趣的小伙伴們可以參考一下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
 "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訪問端口綁定

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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<Startup>()
    .Build();
 
   host.Run();
  }
 }
}

在 Startup.cs 文件中,啟用HTTPS訪問并配置證書路徑及密碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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?}");
   });
 
   //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í)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91久久综合九色综合欧美98 | 精品在线99| 欧美一区二区三区视视频 | 日本一区二区三区国产 | 亚洲精品国产综合久久一线 | 国产精品乱码高清在线观看 | 日本免费一区二区三区四区五六区 | 男人天堂中文字幕 | 特黄一级 | 男人的j进入女人的j免费 | 日本在线视频网址 | youporn在线 | 亚洲色大成网站www久久九九 | 男人女人性生活视频 | 母爱成瘾在线观看 | 亚洲一区二区三区不卡在线播放 | 任你操视频在线观看 | 青草视频在线观看视频 | 久久综合网久久综合 | 草综合 | 国内精品露脸在线视频播放 | 喜欢老头吃我奶躁我的动图 | 精品久久久噜噜噜久久久app | 荡娃艳妇系列小说 | 女人与d0gxxx| 91在线亚洲综合在线 | 天堂8在线天堂资源bt | 免费看打屁股视频的软件 | 国产视频久久久久 | 99re8在这里只有精品23 | 久久成人永久免费播放 | 24adc年龄18岁欢迎大驾光临 | 男人捅女人动漫 | 四虎4hu新地址入口 四虎1515h永久 | 青青热久免费精品视频精品 | 香蕉久久高清国产精品免费 | 太深了 太粗h1v1 | 91制片厂制作果冻传媒破解 | 国产欧美曰韩一区二区三区 | 欧美va在线播放免费观看 | 国产免费一区不卡在线 |