使用SignalR 的客户端去发送消息给使用 https 部署的站点,官方文档目前并没有详细的教程,所以在此记录下步骤:

使用管理员身份打开cmd 窗口,选择一个整数保存文件夹的地址,切换到对应的文件夹,然后执行以下步骤:

(一) 生成证书文件
1. openssl genrsa -out test.key 1024

2. openssl req -new -x509 -key test.key -out test.cer -days 365 -subj /CN=10.158.229.20
注:CN=xxx 这里可以填写部署网站的域名或者IP地址

3. openssl pkcs12 -export -out test.pfx -inkey test.key -in test.cer
注:生成了私钥文件 test.pfx, 这一步需要输入密码,密码会在导入IIS的时候使用

  在以上步骤完成之后,生成如下几个文件, test.cer, test.key, test.pfx:

4. 添加到证书管理的可信任证书节点中区,这一步非常重要,如果不添加,就会导致SignalR无法正常访问

  4.1.  运行-->输入mmc

  4.2. File 中打开证书管理器

  4.3. 在可信任根证书的节点右键导入证书

  

  以上工作便完成了证书的创建和添加

(二)接下来开始部署IIS 站点:

  1. 在IIS 管理其中选择 服务端证书

2. 选择导入,找到对应的 .pfx 证书,输入密码后,确认导入

3. 在自己的站点绑定对应的 SSL 证书

  完成以上工作后,一个https 站点就已经完成

测试Demo:

  客户端:    

 using Microsoft.AspNet.SignalR.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks; namespace SignalR_cli
{
class Program
{
static HubConnection hubConnection = null;
static IHubProxy proxy = null;
static void Main(string[] args)
{
//这里连接使用OpenSSL 生成的证书部署的 https 站点
hubConnection = new HubConnection("https://10.158.229.20:443/");
//var hubConnection = new HubConnection("http://10.158.229.20:8081/");
//请求的时候一定带上对应站点部署的证书
hubConnection.AddClientCertificate(X509Certificate.CreateFromSignedFile(@"E:\cer_demo\myself.cer"));
proxy = hubConnection.CreateHubProxy("ChatHub");
hubConnection.Start();
Console.WriteLine((int)hubConnection.State);
while (true)
{
try
{
Console.WriteLine("Input:");
var msg = Console.ReadLine();
Go(msg);//异步发送消息就好了
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
static async Task Go(string msg)
{
await proxy.Invoke("Send", "userCenter", msg);
}
}
}

  服务端:参考的官方文档

  

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR; namespace Web_SignalR
{
public class ChatHub : Hub
{
public void Send(string name, string message)
{
Clients.All.broadcastMessage(name, message);
}
}
}
 using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin; [assembly: OwinStartup(typeof(Web_SignalR.Startup))] namespace Web_SignalR
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// 有关如何配置应用程序的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkID=316888
app.MapSignalR();
}
}
}
 <!DOCTYPE html>
<html>
<head>
<title>SignalR Simple Chat</title>
<style type="text/css">
.container {
background-color: #99CCFF;
border: thick solid #;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="Send" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div>
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-3.3.1.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.2.2.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>:&nbsp;&nbsp;' + encodedMsg + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val("test");
// Set initial focus to message input box.
$('#message').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#sendmessage').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
</body>
</html>

  效果演示:

  

IIS 使用OpenSSL 生成的自签名证书,然后使用SingalR 客户端访问Https 站点通信的更多相关文章

  1. linux下使用openssl生成 csr crt CA证书

    证书文件生成:一.服务器端1.生成服务器端    私钥(key文件);openssl genrsa -des3 -out server.key 1024运行时会提示输入密码,此密码用于加密key文件( ...

  2. 【Azure 环境】把OpenSSL生产的自签名证书导入到Azure Key Vault Certificate中报错

    问题描述 通过本地生成的自签名证书导入到Azure Key Vault Certificate报错. 错误信息 the specified PEM X.509 certificate content ...

  3. curl+个人证书(又叫客户端证书)访问https站点

    摘自http://blog.csdn.net/chary8088/article/details/22990741 curl+个人证书(又叫客户端证书)访问https站点 目前,大公司的OA管理系统( ...

  4. 用Keytool和OpenSSL生成和签发数字证书

    一)keytool生成私钥文件(.key)和签名请求文件(.csr),openssl签发数字证书      J2SDK在目录%JAVA_HOME%/bin提供了密钥库管理工具Keytool,用于管理密 ...

  5. OPENSSL生成SSL自签证书

    OPENSSL生成SSL自签证书 目前,有许多重要的公网可以访问的网站系统(如网银系统)都在使用自签SSL证书,即自建PKI系统颁发的SSL证书,而不是部署支持浏览器的SSL证书. 支持浏览器的SSL ...

  6. centos7.6使用openssl生成CA签署的证书个人实验笔记

    准备:客户端centos6.10  服务端Centos7.6 实验:客户端生成证书请求,服务端颁发证书,最后吊销其中一个证书 1.先在服务端上的/etc/pki/CA/目录生成rsa的私钥: 2.在服 ...

  7. 一键生成ssl自签名证书脚本

    #!/bin/bash -e # * 为必改项 # * 更换为你自己的域名 CN='' # 例如: demo.rancher.com # 扩展信任IP或域名 ## 一般ssl证书只信任域名的访问请求, ...

  8. C#检测并安装https站点的数字证书,CefSharp和HttpWebRequest通过会话Cookie实现自动登录访问https站点

    HttpUtil工具类: using System; using System.Collections.Generic; using System.IO; using System.Linq; usi ...

  9. requests访问https站点证书告警问题

    背景 想使用api的方式去访问公司内部azkaban平台,https站点,azkaban的官方api文档使用的curl语句,如下: curl -k -X POST --data "actio ...

随机推荐

  1. centos7非centos标准服务 /etc/init.d/service_name start || stop 启动异常

    公司自己写的java程序,在centos7系统执行/etc/init.d/service_name start||stop的时候报错: grafana二次开发的程序 [root@docp1 init. ...

  2. leetcode — spiral-matrix

    import java.util.Arrays; /** * Source : https://oj.leetcode.com/problems/spiral-matrix/ * * Created ...

  3. 【InfluxDB】InfluxDB学习实践笔记

    InfluxDB是用Go编写的一个开源分布式时序.事件和指标数据库,无需外部依赖.它与Elasticsearch.Graphite等类似.比较适用于与事件紧密相关的数据,例如实时日志数据.实时监控数据 ...

  4. 【Flask-RESTPlus系列】Part2:响应编组

    0x00 内容概览 响应编组 基本使用 重命名属性 默认值 自定义字段及多值情况 Url及其他具体字段 复杂结构 列表字段 嵌套字段 api.model()工厂 clone实现复制 api.inher ...

  5. spring-boot(七) 随机端口

    学习文章:springboot小技巧 随机端口 为Spring Cloud的应用实用随机端口非常简单,主要有两种方法: 设置server.port=0,当应用启动的时候会自动的分配一个随机端口,但是该 ...

  6. MySQL:windows中困扰着我们的中文乱码问题

    前言:什么是mysql中的中文乱码问题? 话不多说,直接上图 这个东西困扰了我好久,导致我现在对windows映像非常不好,所以就想改成Linux,行了,牢骚就发到这里,直接说问题,明眼人一眼就看出来 ...

  7. .Net Core实现记录接口执行时间的中间件

    项目中有时接口访问时间过长,但是通过浏览器F12查看时,接口访问时间很正常,所以就很奇怪,于是写一个中间件,记录所有接口访问时间的中间件. 一.中间件 中间件是应用程序处理管道中的组件,用来处理请求和 ...

  8. Python模块之time、datetime

    python内置模块系列(一):time模块与datetime time模块是python内置查看当前时间戳的一个模块 一 time 1 获得时间戳 时间戳:通常来说,时间戳表示的是从1970年1月1 ...

  9. Ubuntu 安装 JDK8 的两种方式

    ubuntu 安装jdk 的两种方式: 1:通过ppa(源) 方式安装. 2:通过官网下载安装包安装. 这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级 使用pp ...

  10. 建立uboot,内核的SI工程(1)

    1. 建立Uboot的SI工程1.1首先给uboot打上补丁,然后来生成压缩文件 tar cjf u-boot- 1.2 编译uboot make 100ask24x0_config //使用打好补丁 ...