2

我们在 Win2003 R2 服务器上使用 Azure ACS 和 WIF,运行 Asp.Net 3.5,一旦 Azure ACS 重定向回我们的站点,就会收到以下异常:

Exception information: 
    Exception type: CryptographicException
    Exception message: The system cannot find the file specified.

at System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope) 
   at Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Encode(Byte[] value)

从研究看来,我们在 IIS 6 中运行网站的 AppPool Identity 可能无法访问相关的加密密钥,但我们还没有找到解决方法。

4

2 回答 2

0

我建议您使用用于该站点的 SSL 证书来加密会话 cookie,并为运行 IIS 应用程序池的用户授予对该证书的私钥的访问权限。

您可以通过以下方式实现前者:

首先,在您的 Application Start 事件中,连接 onServiceConfigurationCreated 事件:

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup
    FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;

}

然后使用以下实现:

void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
    //
    // Use the <serviceCertificate> to protect the cookies that are
    // sent to the client.
    //
    if (e.ServiceConfiguration.ServiceCertificate != null)
    {
        List<CookieTransform> sessionTransforms =
            new List<CookieTransform>(new CookieTransform[] {
                new DeflateCookieTransform(), 
                new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
                new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate)  });
        SessionSecurityTokenHandler sessionHandler = 
            new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
        e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
    }

您需要在 microsoft.identityModel 部分的 Certificates 部分中添加该证书:

  <serviceCertificate>
    <certificateReference x509FindType="FindByThumbprint" findValue="[cert_thumbprint]" />
  </serviceCertificate>

最后,要向运行 App Pool 的用户授予对该证书的私钥的访问权限,请使用:

winhttpcertcfg -g -a "AppPool 账户" -c LOCAL_MACHINE\My -s www.mysite.com

其中,winhttpcertcfg是从这里下载的工具。LOCAL_MACHINE\My证书存储的名称,SSL 证书被定位。“ www.mysite.com ” 是 SSL 证书的主题 (CN) 名称。

我认为这将解决您的问题。如果没有,请带着结果返回这里。

于 2012-05-01T19:50:34.960 回答
0

结果证明,根据另一篇文章,我们必须创建一个简单的 Windows 服务,该服务在与 Windows 2003 R2 上的应用程序池相同的帐户下运行。

于 2012-05-02T12:21:30.527 回答