关于数字证书操作的问题
本人在对安装在客户端的安全证书的操作上遇到问题了,我用.NET FrameWork 里的 makecert.exe 命令生成了一个安全证书 testCert.cer ,然后安装在客户机上。接着编写了如下代码。
index.aspx
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="Test.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<div align="center">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP: 104px" runat="server"
Font-Size="12px">获得客户端的数字证书:</asp:Label>
<asp:Label id="Label2" runat="server">Label</asp:Label>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 331px; POSITION: absolute; TOP: 101px"
runat="server" Font-Size="12px"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 496px; POSITION: absolute; TOP: 101px" runat="server"
Text="提交" Width="48px" Font-Size="12px"></asp:Button></FONT></form>
</div>
</body>
</HTML>

index.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Test
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
//获取客户端的IP地址
String ClientIP;
ClientIP = Request.UserHostAddress;

//获取客户端的主机名
String ClientName;
ClientName = Request.UserHostName;


//获取客户端的数字证书的内容
string mark = "";
HttpClientCertificate cs = Request.ClientCertificate;
mark = cs.Certificate.ToString();

//获取证书的颁发者
string provider = "";
provider = cs.BinaryIssuer.ToString();

/*==================判断数字证书是否存在=====================*/

if (cs.IsPresent == true)
Label2.Text = "数字证书存在";
else
Label2.Text = "数字证书不存在";

//在TextBox里显示数字证书相关内容
TextBox1.Text = provider + mark + ClientIP + ClientName;

}
}
}
编译后,在客户机上运行判断是数字证书不存在。请各位仁兄看看是什么问题?
我给大家提供一个测试的安全证书,请 点击下载 。
如果大家觉得这个测试证书有问题,但我可以告诉大家,我朋友给我发来了个合法的安全证书,我们正常用在邮件加密上了,也不好使。
index.aspx

























index.aspx.cs




















































































编译后,在客户机上运行判断是数字证书不存在。请各位仁兄看看是什么问题?
我给大家提供一个测试的安全证书,请 点击下载 。
如果大家觉得这个测试证书有问题,但我可以告诉大家,我朋友给我发来了个合法的安全证书,我们正常用在邮件加密上了,也不好使。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架