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"); ...
随机推荐
- 前端开发之CSS篇二
主要内容: 一.CSS的继承性和层叠性 二.盒模型 三.padding属性 四.border属性 五.margin属性 六.标准文档流 七.行内元素和块状元素转换 1️⃣ CSS的继承性和层叠性 1 ...
- Android判断Service是否运行
/** * 用来判断服务是否运行. * @param context * @param className 判断的服务名字 * @ret ...
- 61. Rotate List(List)
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given ...
- Python实现常见算法[2]——快速排序
#!/usr/bin/python # module: quik_sort.py def PARTION(L,m,n): base = L[n] i = m-1 j = m while j<n: ...
- CloudStack 初始化执行命令流分析
查询路由元素 选择可以使用的路由元素 需要将网络服务提供者的:虚拟路由和安全同时启用 { "createnetworkresponse" : { ...
- spring4-2-bean配置-9-通过工厂方法配置bean
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjwAAAFICAIAAADbNrOHAAAgAElEQVR4nO2dy7W0uhGFOxWn4JEXAS
- PythonScripter2.7报错ascii codec can't encode characters in position 0-1:ordinal not in range(128)
1. 这是Python 2 mimetypes的bug2. 需要将Python2.7\lib\mimetypes.py文件中如下片段注释或删除:try: ctype = ctype.encode(de ...
- Ubuntu14.04下opencv卸载与重装
参考链接:http://askubuntu.com/questions/334158/installing-opencv http://stackoverflow.com/questions/1313 ...
- 打开程序出现.Net Framework Initialization Error – Unable to find a version of the runtime to run this applicatio的解决办法
部署一个VS2010开发的程序时遇到 了一个非常奇怪的问题,客户端上已经安装了.net framework 4.0,但运行时还是会弹出错误: .Net Framework Initialization ...
- rest-framework-----url控制
一:自定义路由(原始方式) from django.conf.urls import url from app01 import views urlpatterns = [ url(r'^books/ ...