https 基础连接已经关闭: 发送时发生错误。 2020年10月22日 服务器 做项目时,有用到小程序登录接口`https://api.weixin.qq.com/sns/jscode2session`,用`WebRequest`请求这个接口时发生了这个异常错误。 ``` --- 内部异常堆栈跟踪的结尾 --- 在 System.Net.HttpWebRequest.GetResponse() 在 HttpService.Get(String url) 位置 :行号 159 2018-11-13 10:51:17.377 ERROR HttpService: System.Net.WebException: 基础连接已经关闭: 发送时发生错误。 ---> System.IO.IOException: 由于远程方已关闭传输流,身份验证失败。 在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) 在 System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) 在 System.Net.ConnectStream.WriteHeaders(Boolean async) ``` 互联网上说,使用以下代码可以解决问题: ```csharp ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; ``` ### 解决 然而并没什么卵用,但是忽然想到之前为了让小程序的请求生效,需要把https的tls版本弄成tls 1.2,当时把tls 1.0 和tls 1.1的注册表给去掉了,想想可能是这个问题,所有又把tls 1.0 和tls 1.1 的注册表给加上了,然后重启,然后就**成功了**!!!
Windows 服务器启用TLS1.2 2020年10月22日 服务器 [TOC] ## 手动设置 找到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols右键->新建->项->新建TLS 1.1,TLS 1.2 TLS 1.1和TLS 1.2 右键->新建->项->新建Server, Client 在新建的Server和Client中都新建如下的项(DWORD 32位值), 总共4个 DisabledByDefault [Value = 0] Enabled [Value = 1] 如图  ## 直接导入注册表文件 新建一个txt文件,填写写入以下内容,然后更改后缀为reg,双击运行 ``` Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server] "Enabled"=dword:00000000 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server] "Enabled"=dword:00000000 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001 ``` ## 用 IISCrypto.exe 这个软件可以非常方便的开启关闭TLS  [Nartac Software - IIS Crypto](https://www.nartac.com/Products/IISCrypto) **PS:这些操作之后都需要重启服务器** ## 参考链接 [TLS-SSL Settings | Microsoft Docs](https://docs.microsoft.com/zh-cn/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn786418%28v%3dws.11%29) [STARTTLS | 维基百科,自由的百科全书](https://zh.wikipedia.org/zh-hans/STARTTLS)
asp.net 设置设置默认首页 2020年10月22日 服务器 网站开发 [TOC] ### IIS7 操作 功能视图 => 默认文档 => 添加 ### 修改web.config 文件 ```xml <defaultDocument> <files> <add value="index.aspx" /> </files> </defaultDocument> ``` > 要放在 `system.webServer` 节点下