我正在使用此代码通过其指纹查找证书.证书存在于个人证书存储区中,但此代码未找到该证书.
请告诉我我在哪里做错了.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string certThumbPrint = "??fe14593dd66b2406c5269d742d04b6e1ab03adb1";
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
// Try to open the store.
certStore.Open(OpenFlags.ReadOnly);
// Find the certificate that matches the thumbprint.
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint, certThumbPrint, false);
certStore.Close();
// Check to see if our certificate was added to the collection. If no,
// throw an error, if yes, create a certificate using it.
if (0 == certCollection.Count)
{
Console.WriteLine("Error: No certificate found …Run Code Online (Sandbox Code Playgroud) netsh命令想要一个appid(见这里):
netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00112233-4455-6677-8899-AABBCCDDEEFF}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我还无法理解我应该如何知道GUID netsh要我提供的内容.任何提示?
似乎有很多令人困惑的,有时是冲突的信息,关于使.net HTTPListener https能够.我的理解如下:
一个人的c#代码需要一个https前缀(例如https://*:8443),以便监听器理解它需要在此端口上为SSL请求提供服务.
实际的SSL握手发生在幕后并由http.sys(安装在Windows机器上的某处)进行处理; C#代码不必显式管理ssl握手,因为它发生在封面下.
需要在计算机上安装"x509可信证书" httpListener,并且某种程度上证书需要绑定到端口8443(在此示例中)
我的理解是否正确?如果没有,请教育我.
关于x509证书,我的理解是:
makecert创建X509证书.此证书存储在个人存储中,需要转移到可信存储(这是http侦听器所在的位置).似乎我可以certMgr用来执行移动,或者我可以mmc用来实现移动.似乎还有超过1 X509证书格式(DER,Base64,pks,PSWD保护pks私有等)..有,我应该使用首选格式?一旦我将证书带入可信商店,我就需要将它绑定到tcp端口.我在Win7上:我应该使用httpcfg还是netsh?
任何提示/建议将不胜感激.
当您最初设置IIS Express以启用SSL时,它会将端口默认为44300.不幸的是,当我尝试访问我的网站时,https://localhost/它不起作用,除非我使用端口号44300 - https://localhost:44300/.
使用以下内容生成链接:
<%= Html.ActionLink("Index", "Index", "Home", new { @action = "https://" + Request.Hostname + Url.Action("Index", "Home") }) %>
Run Code Online (Sandbox Code Playgroud)
虽然这是一个丑陋的解决方案,但@action关键字可以覆盖生成的路由,但这意味着应用程序似乎需要知道任何非标准端口(例如44300).
问题在于我会写一些东西来解决只会在开发环境中出现的问题.
所以我的问题是......如何将端口更改为443并让IIS Express像这样?
我的网站配置如下:
<site name="MySite" id="2" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="C:\Inetpub\MySite" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":80:" />
<binding protocol="https" bindingInformation=":44300:" />
</bindings>
</site>
Run Code Online (Sandbox Code Playgroud)
提前谢谢了.
更新:
Divya已经在IIS论坛上回答了这个问题.
ssl ×2
.net ×1
asp.net-mvc ×1
c# ×1
httplistener ×1
https ×1
iis-express ×1
netsh ×1
wcf ×1
windows ×1