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

服務器之家:專注于服務器技術及軟件下載分享
分類導航

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

服務器之家 - 編程語言 - 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教程

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

最近要做一個項目,正逢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

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品久久99麻豆蜜桃666 | porono日本动漫| 亚洲欧美天堂综合久久 | 天美传媒果冻传媒星空传媒 | 日韩一区二区三区免费 | 久久国产乱子伦免费精品 | 国产精品中文 | 俄罗斯一级成人毛片 | 国产精品日韩欧美一区二区 | 插得好舒服| 龟甲情感超市全文阅读 小说 | 欧美日韩在线一区二区三区 | 国内揄拍国内精品久久 | 国产精品第一区揄拍 | 污软件在线观看 | 成年人免费观看视频网站 | 午夜无码片在线观看影院 | 免费网站视频 | 荡娃艳妇有声小说 | 吉川爱美与黑人解禁 | 精品四虎 | 第一福利在线观看永久视频 | 亚洲 欧美 成人 | 午夜影院小视频 | 国产精品久久现线拍久青草 | 亚洲精品91 | 国产精品麻豆免费版 | 日本高清中文字幕 | 亚洲国产在线99视频 | 亚洲精品成人a | ai换脸杨颖啪啪免费网站 | 青青网| 日本免费在线观看视频 | 国产农村乱子伦精品视频 | 3d欧美人禽交 | 国产精品久久毛片蜜月 | 国产精品亚洲片夜色在线 | 九九热这里只有精品视频免费 | 欧美ay| 日本在线观看视频网站 | 色淫影院 |