In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how ASP.NET Core 1.0 deploys HTTPS. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I'm going to work on a project recently, which coincides with the official release of ASP.Net Core version 1.0. Due to the security requirements of the modern Internet, HTTPS encrypted communication has become the mainstream, so there is this scheme.
This solution is inspired by an old solution:
ASP.NET Core 1.0 deployment 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
After repeatedly searching the official documents and trying again and again, we come up with the following solution
In project.json, add the reference Microsoft.AspNetCore.Server.Kestrel.Https
{"dependencies": {/ / Cross-platform reference / / "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": {/ / Cross-platform reference / / "netcoreapp1.0": {/ / "imports": [/ / "dotnet5.6" / / "portable-net45+win8" / Windows platform generalization references "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%"]}}
In Program.cs, add HTTPS access port binding
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 () .build (); host.Run ();}
In the Startup.cs file, enable HTTPS access and configure the certificate path and password
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) .AddEnvironmental variables (); 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 (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 ");}) Thank you for your reading! This is the end of the article on "how to deploy HTTPS in ASP.NET Core 1.0". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.