Windows IIS ASP.NET Core中创建和使用HTTPS自签名证书
为什么要用Https就不说了。
第一步:创建自签名的证书。在Windows下开启PowerShell,将以下文字粘贴进去:
- # setup certificate properties including the commonName (DNSName) property for Chrome 58+
- $certificate = New-SelfSignedCertificate `
- -Subject 改成自己想要的标题不要带乱七八糟的符号(安装证书的时候会显示这个) `
- -DnsName 友好域名 `
- -KeyAlgorithm RSA `
- -KeyLength 2048 `
- -NotBefore (Get-Date) `
- -NotAfter (Get-Date).AddYears(2) `
- -CertStoreLocation "cert:CurrentUser\My" `
- -FriendlyName "证书的友好名称,在IIS指定的时候显示Certificate for .NET Core" `
- -HashAlgorithm SHA256 `
- -KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
- -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
- $certificatePath = 'Cert:\CurrentUser\My\' + ($certificate.ThumbPrint)
- # create temporary certificate path
- $tmpPath = "C:\tmp"
- If(!(test-path $tmpPath))
- {
- New-Item -ItemType Directory -Force -Path $tmpPath
- }
- # set certificate password here
- $pfxPassword = ConvertTo-SecureString -String "证书的密码" -Force -AsPlainText
- $pfxFilePath = "c:\tmp\证书的名称.pfx"
- $cerFilePath = "c:\tmp\证书的名称.cer"
- # create pfx certificate
- Export-PfxCertificate -Cert $certificatePath -FilePath $pfxFilePath -Password $pfxPassword
- Export-Certificate -Cert $certificatePath -FilePath $cerFilePath
- # import the pfx certificate
- Import-PfxCertificate -FilePath $pfxFilePath Cert:\LocalMachine\My -Password $pfxPassword -Exportable
- # trust the certificate by importing the pfx certificate into your trusted root
- Import-Certificate -FilePath $cerFilePath -CertStoreLocation Cert:\CurrentUser\Root
- # optionally delete the physical certificates (don’t delete the pfx file as you need to copy this to your app directory)
- # Remove-Item $pfxFilePath
- Remove-Item $cerFilePath
把汉字部分修改成你想要的,然后运行一下,就可以在C:\tmp下面找到你的证书了,一般把它放在网站根目录下即可。
二、站点配置(ASP.NET Core 2.1)
* public void ConfigureServices(IServiceCollection services) 部分:
services.AddMvc(options =>
{
options.Filters.Add(new RequireHttpsAttribute());//所有请求都使用HTTPS
})
* public void Configure(IApplicationBuilder app, IHostingEnvironment env) 部分:
var options = new RewriteOptions().AddRedirectToHttps();
app.UseRewriter(options);
app.UseHttpsRedirection();
三、IIS配置:
经过这几步,你的网站就变成Https的了。
Windows IIS ASP.NET Core中创建和使用HTTPS自签名证书的更多相关文章
- Asp.Net Core中创建多DbContext并迁移到数据库
在我们的项目中我们有时候需要在我们的项目中创建DbContext,而且这些DbContext之间有明显的界限,比如系统中两个DbContext一个是和整个数据库的权限相关的内容而另外一个DbConte ...
- 在ASP.NET Core中创建基于Quartz.NET托管服务轻松实现作业调度
在这篇文章中,我将介绍如何使用ASP.NET Core托管服务运行Quartz.NET作业.这样的好处是我们可以在应用程序启动和停止时很方便的来控制我们的Job的运行状态.接下来我将演示如何创建一个简 ...
- 在ASP.NET Core中创建自定义端点可视化图
在上篇文章中,我为构建自定义端点可视化图奠定了基础,正如我在第一篇文章中展示的那样.该图显示了端点路由的不同部分:文字值,参数,动词约束和产生结果的端点: 在本文中,我将展示如何通过创建一个自定义的D ...
- 【半译】在ASP.NET Core中创建内部使用作用域服务的Quartz.NET宿主服务
在我的上一篇文章中,我展示了如何使用ASP.NET Core创建Quartz.NET托管服务并使用它来按计划运行后台任务.不幸的是,由于Quartz.NET API的工作方式,在Quartz作业中使用 ...
- ASP.NET Core中Middleware的使用
https://www.cnblogs.com/shenba/p/6361311.html ASP.NET 5中Middleware的基本用法 在ASP.NET 5里面引入了OWIN的概念,大致意 ...
- 重学ASP.NET Core 中的标记帮助程序
标记帮助程序是什么 标记帮助程序使服务器端代码可以在 Razor 文件中参与创建和呈现 HTML 元素. 例如,内置的 ImageTagHelper 可以将版本号追加到图片名称. 每当图片发生变化时 ...
- 如何在ASP.NET Core 中使用IHttpClientFactory
利用IHttpClientFactory可以无缝创建HttpClient实例,避免手动管理它们的生命周期. 当使用ASP.Net Core开发应用程序时,可能经常需要通过HttpClient调用Web ...
- 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】
Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...
- ASP.NET Core中使用表达式树创建URL
当我们在ASP.NET Core中生成一个action的url会这样写: var url=_urlHelper.Action("Index", "Home"); ...
随机推荐
- spring 提供的属性值拷贝工具类
当需要把一个原生的类中属性拷贝到扩展类中时,使用以下类很方便:
- jsp出现getOutputStream() has already been called for this response异常的原因和解决方法
jsp出现getOutputStream() has already been called for this response异常的原因和解决方法 在tomcat5下jsp中出现此错误一般都是在js ...
- SqlServer垂直分表 如何减少程序改动
当单表数据太多时,我们可以水平划分,参考 SqlServer 分区视图实现水平分表 ,水平划分可以提高表的一些性能. 而 垂直分表 则相对很少见到和用到,因为这可能是数据库设计上的问题了.如果数据库中 ...
- 设计模式--适配器模式(Adapter)详解
适配器模式将某个类的接口转换成客户端期望的另一个接口表示,目的是消除由于接口不匹配所造成的类的兼容性问题.主要分为三类:类的适配器模式.对象的适配器模式.接口的适配器模式. 01.类的适配器模式 核心 ...
- [C++] Sign and magnitude,Ones' complement and Two's complement
Sign and magnitude,Ones' complement and Two's complement
- [C++] struct memory allocation
MAX-byte alignment (最大单位对齐) typedef struct user USER; typedef struct employee E; struct user{ ]; //t ...
- Scala入门学习随笔
推荐学习视频:慕课网http://www.imooc.com/learn/613,讲师:辰风 ScalaAPI:http://www.scala-lang.org/api/current/#packa ...
- [GO]匿名字段
package main import ( "fmt" ) type Person struct { name string sex byte age int } type Stu ...
- JSTL 引入
首先要明白jstl有如下版本: jstl1.0的引入方式为: <taglib uri="http://java.sun.com/jstl/core" prefix=&quo ...
- firefox ubuntu 中文包
sudo apt-get install firefox-locale-zh-hans