C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器) - C/S框架网原创
C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器) - C/S框架网原创
C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器)



C# Code:
private void btnBinding_Click(object sender, EventArgs e)
{
try
{
var fileName = txtFileName.Text;
var cert = new X509Certificate2(fileName, txtPwd.Text);
string hash = cert.GetCertHashString();
//组合http add sslcert命令
string cmd = string.Format("netsh http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2}",
txtPort.Text, hash, "{" + Guid.NewGuid().ToString().ToLower() + "}");
ProcessStartInfo p = new ProcessStartInfo();
p.Verb = "runas";//将启动进程的身份运行以【管理员】身份运行
p.FileName = "cmd.exe";
p.UseShellExecute = false;
p.RedirectStandardInput = true;
p.RedirectStandardOutput = true;
p.RedirectStandardError = true;
p.CreateNoWindow = true;
Process ps = Process.Start(p);
ps.StandardInput.WriteLine(cmd);
ps.StandardInput.WriteLine("exit");
ps.StandardInput.AutoFlush = true;
string OutPut = ps.StandardOutput.ReadToEnd();
ps.WaitForExit();
ps.Close();
txtOutput.Text = OutPut;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
private void btnBinding_Click(object sender, EventArgs e)
{
try
{
var fileName = txtFileName.Text;
var cert = new X509Certificate2(fileName, txtPwd.Text);
string hash = cert.GetCertHashString();
//组合http add sslcert命令
string cmd = string.Format("netsh http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2}",
txtPort.Text, hash, "{" + Guid.NewGuid().ToString().ToLower() + "}");
ProcessStartInfo p = new ProcessStartInfo();
p.Verb = "runas";//将启动进程的身份运行以【管理员】身份运行
p.FileName = "cmd.exe";
p.UseShellExecute = false;
p.RedirectStandardInput = true;
p.RedirectStandardOutput = true;
p.RedirectStandardError = true;
p.CreateNoWindow = true;
Process ps = Process.Start(p);
ps.StandardInput.WriteLine(cmd);
ps.StandardInput.WriteLine("exit");
ps.StandardInput.AutoFlush = true;
string OutPut = ps.StandardOutput.ReadToEnd();
ps.WaitForExit();
ps.Close();
txtOutput.Text = OutPut;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
C# Code:
private void btnDelete_Click(object sender, EventArgs e)
{
string cmd = string.Format("netsh http delete sslcert 0.0.0.0:{0}", txtPort.Text);
Process p = new Process();
p.StartInfo.Verb = "runas";//将启动进程的身份运行以【管理员】身份运行
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");
txtOutput.Text = p.StandardOutput.ReadToEnd();
p.Close();
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
private void btnDelete_Click(object sender, EventArgs e)
{
string cmd = string.Format("netsh http delete sslcert 0.0.0.0:{0}", txtPort.Text);
Process p = new Process();
p.StartInfo.Verb = "runas";//将启动进程的身份运行以【管理员】身份运行
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");
txtOutput.Text = p.StandardOutput.ReadToEnd();
p.Close();
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
C# Code:
private void btnQuery_Click(object sender, EventArgs e)
{
string cmd = "netsh http show sslcert";
Process p = new Process();
p.StartInfo.Verb = "runas";//将启动进程的身份运行以【管理员】身份运行
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");
txtOutput.Text = p.StandardOutput.ReadToEnd();
p.Close();
int i = txtOutput.Text.IndexOf(txtPort.Text);
if (i > 0)
{
txtOutput.Focus();
txtOutput.SelectionStart = i;
txtOutput.SelectionLength = txtPort.Text.Length;
txtOutput.ScrollToCaret();
}
else
{
txtOutput.Text = "查询无此端口!";
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
private void btnQuery_Click(object sender, EventArgs e)
{
string cmd = "netsh http show sslcert";
Process p = new Process();
p.StartInfo.Verb = "runas";//将启动进程的身份运行以【管理员】身份运行
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");
txtOutput.Text = p.StandardOutput.ReadToEnd();
p.Close();
int i = txtOutput.Text.IndexOf(txtPort.Text);
if (i > 0)
{
txtOutput.Focus();
txtOutput.SelectionStart = i;
txtOutput.SelectionLength = txtPort.Text.Length;
txtOutput.ScrollToCaret();
}
else
{
txtOutput.Text = "查询无此端口!";
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761

程序名:CSFramework.WebApi.BindingSSLCert
适用以下WebApi服务承载Hosting方式:
1. 自承载WebApi服务器:CSFramework.WebApi.ServerSelfHosting
2. Win服务承载WebApi服务器:CSFramework.WebApi.Server
.NET WebApi开发框架|MVC框架|后端框架|服务端框架-标准版V1.0
适用开发:快速构建支持多种客户端的服务端程序,支持APP、B/S、C/S跨平台移动终端等。
运行平台:Windows + .NET Framework 4.5
开发工具:Visual Studio 2015+,C#语言
数据库:Microsoft SQLServer 2008R2+(支持多数据库:Oracle/MySql)
参考文档:
微信小程序使用https协议的WebApi后端应用服务(Win服务宿主或自承载)
原创WebApi框架:采用HTTPS协议SelfHosting,Windows服务承载WebApi服务
C# ASP.NET WebApi服务器搭建详解 - Win服务承载(Windows Service Hosting宿主)
WCF顶级安全:HTTPS协议SSL证书+Windows认证+TransportWithMessageCredential安全模式
IIS部署ssl证书支持https协议
C#.NET IP地址工具类WebAPI服务器使用
阿里云虚拟主机部署ssl证书支持https协议
ASPNET WebApi服务器三种承载方式:SelfHosting,IIS Hosting, WinService Hosting
C# ASP.NET WebApi服务器搭建详解 - 自承载(Self Hosting)
C# ASP.NET WebApi服务器搭建详解 - IIS服务承载(IIS Hosting IIS宿主)
C/S软件授权注册系统V3.0(Winform+WebApi+.NET8+EFCore版本)|C/S开发框架
.Net开发服务器服务端应用程序 - WebApi后端开发框架
WCF开发框架-客户端采用Windows身份认证调用HTTPS协议WCF接口
.Net后端框架|WebApi服务端开发框架|C/S框架网原创作品
解决方案:IIS服务器更换https SSL证书后客户端不能访问
阿里云购买免费版个人SSL证书 - 微信小程序后端应用服务必须是HTTPS协议
微信小程序使用https协议的WebApi后端应用服务(Win服务宿主或自承载)
原创WebApi框架:采用HTTPS协议SelfHosting,Windows服务承载WebApi服务
C# ASP.NET WebApi服务器搭建详解 - Win服务承载(Windows Service Hosting宿主)
WCF顶级安全:HTTPS协议SSL证书+Windows认证+TransportWithMessageCredential安全模式
IIS部署ssl证书支持https协议
C#.NET IP地址工具类WebAPI服务器使用
阿里云虚拟主机部署ssl证书支持https协议
ASPNET WebApi服务器三种承载方式:SelfHosting,IIS Hosting, WinService Hosting
C# ASP.NET WebApi服务器搭建详解 - 自承载(Self Hosting)
C# ASP.NET WebApi服务器搭建详解 - IIS服务承载(IIS Hosting IIS宿主)
C/S软件授权注册系统V3.0(Winform+WebApi+.NET8+EFCore版本)|C/S开发框架
.Net开发服务器服务端应用程序 - WebApi后端开发框架
WCF开发框架-客户端采用Windows身份认证调用HTTPS协议WCF接口
.Net后端框架|WebApi服务端开发框架|C/S框架网原创作品
解决方案:IIS服务器更换https SSL证书后客户端不能访问
阿里云购买免费版个人SSL证书 - 微信小程序后端应用服务必须是HTTPS协议
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
在线客服

