麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:31:03
字體:
來源:轉載
供稿:網友

最近要做一個項目,正逢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<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?}");   });   //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");   });  } }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到ASP.NET教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品成人久久 | 亚洲午夜精选 | 大胆在线日本aⅴ免费视频 美国黄色毛片女人性生活片 | 黄网站在线观 | 成人9禁啪啪无遮挡免费 | 久久精品观看 | 亚洲自拍第二页 | 九草av| 国产午夜精品久久久久久免费视 | 久久精品a一级国产免视看成人 | 黄色免费大片 | 一级毛片免费高清 | 精品一区久久久 | 97中文| 91国在线高清视频 | 亚洲国产精品久久久久久久久 | 91小视频在线观看免费版高清 | 欧美日韩在线视频观看 | 中文字幕免费在线观看视频 | 嗯~啊~弄嗯~啊h高潮视频 | 日本看片一区二区三区高清 | 婷婷亚洲一区二区三区 | 国产免费v片 | 少妇的肉体的满足毛片 | 免费国产a | 调教小男生抽打尿孔嗯啊视频 | 蜜桃传免费看片www 一本色道精品久久一区二区三区 | 久久久tv| 久久免费观看一级毛片 | 欧美a在线看 | 在线中文字幕观看 | 香蕉国产9 | 久国产 | 久久久久北条麻妃免费看 | 欧美视频一区二区三区四区 | 国产精品剧情一区二区在线观看 | 91福利影视 | 国产免费视频一区二区裸体 | 亚洲一区二区在线视频 | 成人午夜影院 | 国产老师做www爽爽爽视频 |