为什么要用Https就不说了。

第一步:创建自签名的证书。在Windows下开启PowerShell,将以下文字粘贴进去:

  1. # setup certificate properties including the commonName (DNSName) property for Chrome 58+
  2. $certificate = New-SelfSignedCertificate `
  3. -Subject 改成自己想要的标题不要带乱七八糟的符号(安装证书的时候会显示这个) `
  4. -DnsName 友好域名 `
  5. -KeyAlgorithm RSA `
  6. -KeyLength 2048 `
  7. -NotBefore (Get-Date) `
  8. -NotAfter (Get-Date).AddYears(2) `
  9. -CertStoreLocation "cert:CurrentUser\My" `
  10. -FriendlyName "证书的友好名称,在IIS指定的时候显示Certificate for .NET Core" `
  11. -HashAlgorithm SHA256 `
  12. -KeyUsage DigitalSignature, KeyEncipherment, DataEncipherment `
  13. -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
  14. $certificatePath = 'Cert:\CurrentUser\My\' + ($certificate.ThumbPrint)
  15.  
  16. # create temporary certificate path
  17. $tmpPath = "C:\tmp"
  18. If(!(test-path $tmpPath))
  19. {
  20. New-Item -ItemType Directory -Force -Path $tmpPath
  21. }
  22.  
  23. # set certificate password here
  24. $pfxPassword = ConvertTo-SecureString -String "证书的密码" -Force -AsPlainText
  25. $pfxFilePath = "c:\tmp\证书的名称.pfx"
  26. $cerFilePath = "c:\tmp\证书的名称.cer"
  27.  
  28. # create pfx certificate
  29. Export-PfxCertificate -Cert $certificatePath -FilePath $pfxFilePath -Password $pfxPassword
  30. Export-Certificate -Cert $certificatePath -FilePath $cerFilePath
  31.  
  32. # import the pfx certificate
  33. Import-PfxCertificate -FilePath $pfxFilePath Cert:\LocalMachine\My -Password $pfxPassword -Exportable
  34.  
  35. # trust the certificate by importing the pfx certificate into your trusted root
  36. Import-Certificate -FilePath $cerFilePath -CertStoreLocation Cert:\CurrentUser\Root
  37.  
  38. # optionally delete the physical certificates (don’t delete the pfx file as you need to copy this to your app directory)
  39. # Remove-Item $pfxFilePath
  40. 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自签名证书的更多相关文章

  1. Asp.Net Core中创建多DbContext并迁移到数据库

    在我们的项目中我们有时候需要在我们的项目中创建DbContext,而且这些DbContext之间有明显的界限,比如系统中两个DbContext一个是和整个数据库的权限相关的内容而另外一个DbConte ...

  2. 在ASP.NET Core中创建基于Quartz.NET托管服务轻松实现作业调度

    在这篇文章中,我将介绍如何使用ASP.NET Core托管服务运行Quartz.NET作业.这样的好处是我们可以在应用程序启动和停止时很方便的来控制我们的Job的运行状态.接下来我将演示如何创建一个简 ...

  3. 在ASP.NET Core中创建自定义端点可视化图

    在上篇文章中,我为构建自定义端点可视化图奠定了基础,正如我在第一篇文章中展示的那样.该图显示了端点路由的不同部分:文字值,参数,动词约束和产生结果的端点: 在本文中,我将展示如何通过创建一个自定义的D ...

  4. 【半译】在ASP.NET Core中创建内部使用作用域服务的Quartz.NET宿主服务

    在我的上一篇文章中,我展示了如何使用ASP.NET Core创建Quartz.NET托管服务并使用它来按计划运行后台任务.不幸的是,由于Quartz.NET API的工作方式,在Quartz作业中使用 ...

  5. ASP.NET Core中Middleware的使用

    https://www.cnblogs.com/shenba/p/6361311.html   ASP.NET 5中Middleware的基本用法 在ASP.NET 5里面引入了OWIN的概念,大致意 ...

  6. 重学ASP.NET Core 中的标记帮助程序

    标记帮助程序是什么 标记帮助程序使服务器端代码可以在 Razor 文件中参与创建和呈现 HTML 元素. 例如,内置的 ImageTagHelper 可以将版本号追加到图片名称.  每当图片发生变化时 ...

  7. 如何在ASP.NET Core 中使用IHttpClientFactory

    利用IHttpClientFactory可以无缝创建HttpClient实例,避免手动管理它们的生命周期. 当使用ASP.Net Core开发应用程序时,可能经常需要通过HttpClient调用Web ...

  8. 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 创 ...

  9. ASP.NET Core中使用表达式树创建URL

    当我们在ASP.NET Core中生成一个action的url会这样写: var url=_urlHelper.Action("Index", "Home"); ...

随机推荐

  1. spring 提供的属性值拷贝工具类

    当需要把一个原生的类中属性拷贝到扩展类中时,使用以下类很方便:

  2. jsp出现getOutputStream() has already been called for this response异常的原因和解决方法

    jsp出现getOutputStream() has already been called for this response异常的原因和解决方法 在tomcat5下jsp中出现此错误一般都是在js ...

  3. SqlServer垂直分表 如何减少程序改动

    当单表数据太多时,我们可以水平划分,参考 SqlServer 分区视图实现水平分表 ,水平划分可以提高表的一些性能. 而 垂直分表 则相对很少见到和用到,因为这可能是数据库设计上的问题了.如果数据库中 ...

  4. 设计模式--适配器模式(Adapter)详解

    适配器模式将某个类的接口转换成客户端期望的另一个接口表示,目的是消除由于接口不匹配所造成的类的兼容性问题.主要分为三类:类的适配器模式.对象的适配器模式.接口的适配器模式. 01.类的适配器模式 核心 ...

  5. [C++] Sign and magnitude,Ones' complement and Two's complement

    Sign and magnitude,Ones' complement and Two's complement

  6. [C++] struct memory allocation

    MAX-byte alignment (最大单位对齐) typedef struct user USER; typedef struct employee E; struct user{ ]; //t ...

  7. Scala入门学习随笔

    推荐学习视频:慕课网http://www.imooc.com/learn/613,讲师:辰风 ScalaAPI:http://www.scala-lang.org/api/current/#packa ...

  8. [GO]匿名字段

    package main import ( "fmt" ) type Person struct { name string sex byte age int } type Stu ...

  9. JSTL 引入

    首先要明白jstl有如下版本:  jstl1.0的引入方式为: <taglib uri="http://java.sun.com/jstl/core" prefix=&quo ...

  10. firefox ubuntu 中文包

    sudo apt-get install firefox-locale-zh-hans