如何授予ASP.NET访问证书存储区中证书的私钥的权限?

我有一个ASP.NET应用程序,可以访问证书存储区中证书的私钥。在Windows Server 2003上,我能够使用winhttpcertcfg.exe授予对NETWORK SERVICE帐户的私钥访问权限。如何在IIS 7.5网站中的Windows Server 2008 R2上授予访问证书存储区(本地计算机\个人)中证书的私钥的权限?


我尝试授予对“每个人”,“ IIS AppPool \ DefaultAppPool”,“ IIS_IUSRS”和我可以使用证书MMC(Server 2008 R2)找到的所有其他安全帐户的完全信任访问权限。但是,以下代码演示该代码无权访问随私钥一起导入的证书的私钥。每次访问私钥属性时,代码都会引发错误。


Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Repeater ID="repeater1" runat="server">

            <HeaderTemplate>

                <table>

                    <tr>

                        <td>

                            Cert

                        </td>

                        <td>

                            Public Key

                        </td>

                        <td>

                            Private Key

                        </td>

                    </tr>

            </HeaderTemplate>

            <ItemTemplate>

                <tr>

                    <td>

                    <%#((X509Certificate2)Container.DataItem).GetNameInfo(X509NameType.SimpleName, false) %>

                    </td>

                    <td>

                    <%#((X509Certificate2)Container.DataItem).HasPublicKeyAccess() %>

                    </td>

                    <td>

                    <%#((X509Certificate2)Container.DataItem).HasPrivateKeyAccess() %>

                    </td>

                </tr>

            </ItemTemplate>

            <FooterTemplate>

                </table></FooterTemplate>

        </asp:Repeater>

    </div>

    </form>

</body>

</html>


炎炎设计
浏览 511回答 3
3回答

白衣染霜花

关于通过MMC,证书,选择证书,右键单击所有任务,“管理私钥”授予权限的说明“管理私钥”仅在“个人...”的菜单列表中。因此,如果将证书放入“受信任的人”等中,那么您将很不走运。我们找到了一种对我们有用的方法。将证书拖放到“个人”,执行“管理私钥”以授予权限。记住要设置为使用对象类型内置函数,并使用本地计算机而非域。我们授予了DefaultAppPool用户权限,并保留了该权限。完成后,将证书拖放回原来的位置。Presto。

慕桂英546537

我想出了在Powershell中有人问过的方法:$keyname=(((gci cert:\LocalMachine\my | ? {$_.thumbprint -like $thumbprint}).PrivateKey).CspKeyContainerInfo).UniqueKeyContainerName$keypath = $env:ProgramData + “\Microsoft\Crypto\RSA\MachineKeys\”$fullpath=$keypath+$keyname$Acl = Get-Acl $fullpath$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS AppPool\$iisAppPoolName", "Read", "Allow")$Acl.SetAccessRule($Ar)Set-Acl $fullpath $Acl
打开App,查看更多内容
随时随地看视频慕课网APP