C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器) - C/S框架网原创
作者:C/S框架网|www.cscode.ne  发布日期:2020/02/12 04:10:29
  C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器) - C/S框架网原创

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


C#.NET IP端口绑定SSL证书支持HTTPS协议(用于Win服务自承载WebApi服务器) 


贴图图片-IP端口绑定证书


贴图图片-IP端口绑定证书1


贴图图片-IP端口绑定证书2



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



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 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



贴图图片-IP端口绑定证书3

程序名: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)


VS.NET后端框架,C#.NET开发的服务器端开发框架 - C/S框架网





上一篇 下一篇