欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2016年07月11日 10:01:13   作者:歐陽敏嵐VicBilibily  
這篇文章主要為大家詳細介紹了ASP.NET Core 1.0 部署 HTTPS(.NET Core 1.0),感興趣的小伙伴們可以參考一下

最近要做一個項目,正逢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=tuicool&utm_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()
    .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");
   });

  }
 }
}

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

相關(guān)文章

  • .NET Core利用skiasharp文字頭像生成方法教程(基于docker發(fā)布)

    .NET Core利用skiasharp文字頭像生成方法教程(基于docker發(fā)布)

    這篇文章主要給大家介紹了關(guān)于.NET Core利用skiasharp文字頭像生成(基于docker發(fā)布)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • httpHandler實現(xiàn).Net無后綴名Web訪問的實現(xiàn)解析

    httpHandler實現(xiàn).Net無后綴名Web訪問的實現(xiàn)解析

    有時候我們看到很多網(wǎng)站是網(wǎng)址是沒有后綴名的,其實.net中可以通過httpHandler來實現(xiàn)。
    2011-10-10
  • asp.net點選驗證碼實現(xiàn)思路分享 (附demo)

    asp.net點選驗證碼實現(xiàn)思路分享 (附demo)

    這篇文章主要介紹了asp.net點選驗證碼實現(xiàn)思路分享 (附demo),具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-01-01
  • .NET?MCP?文檔詳細指南

    .NET?MCP?文檔詳細指南

    本文檔詳細介紹了?.NET?使用?MCP?的相關(guān)內(nèi)容,包括服務(wù)器端實現(xiàn)、客戶端實現(xiàn)以及?Cursor?集成配置等方面,通過使用?MCP,開發(fā)者可以創(chuàng)建強大的工具和服務(wù),使?AI?模型能夠安全地訪問和操作各種數(shù)據(jù)源,感興趣的朋友一起看看吧
    2025-04-04
  • .NET  Visual Studio 代碼性能分析工具

    .NET Visual Studio 代碼性能分析工具

    大家都知道性能優(yōu)化對程序員至關(guān)重要,一個小問題可能導(dǎo)致程序癱瘓,這里我就給大家介紹如何使用工具幫助程序員進行代碼性能優(yōu)化,需要的朋友可以參考下
    2015-07-07
  • 生成代碼從T到T1、T2、Tn自動生成多個類型的泛型實例代碼

    生成代碼從T到T1、T2、Tn自動生成多個類型的泛型實例代碼

    這篇文章主要給大家介紹了關(guān)于生成代碼從T到T1、T2、Tn自動生成多個類型的泛型的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起看看吧
    2018-09-09
  • 如何取得Repeater控件選擇的項目及注意事項

    如何取得Repeater控件選擇的項目及注意事項

    Repeater控件,每個item前有一個CheckBox,把選擇的item列顯出來,有兩個地方需要注意的,就是CheckBox與Label,這個Label是隨你需要獲取的內(nèi)容而變化喔。如你想獲取Nickname,那你需要把綁定的的內(nèi)容放在Label上
    2013-01-01
  • Asp.net 網(wǎng)站性能優(yōu)化二則分享

    Asp.net 網(wǎng)站性能優(yōu)化二則分享

    Web服務(wù)器的性能優(yōu)化有很多資料介紹了,多臺主機負載均衡,查詢結(jié)果的多級緩存,數(shù)據(jù)庫索引優(yōu)化等都是常見的優(yōu)化手段。
    2011-08-08
  • 利用Asp.Net回調(diào)機制實現(xiàn)進度條

    利用Asp.Net回調(diào)機制實現(xiàn)進度條

    本文將利用Asp.Net的回調(diào)機制使用Js實現(xiàn)一個簡易進度條
    2009-01-01
  • asp.net JSONHelper JSON幫助類

    asp.net JSONHelper JSON幫助類

    asp.net JSONHelper JSON幫助類
    2010-01-01

最新評論