Win2003 R2上使用Azure ACS和Asp.Net 3.5的WIF例外

时间:2012-05-01 11:44:32

标签: asp.net .net-3.5 azure iis-6 wif

我们在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可能无法访问相关的加密密钥,但是我们还没有找到解决方法。

2 个答案:

答案 0 :(得分:0)

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

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

首先,在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部分的“证书”部分添加该证书:

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

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

  

winhttpcertcfg -g -a“AppPool帐户”-c LOCAL_MACHINE \ My -s   www.mysite.com

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

我认为这将解决您的问题。如果没有,请回到这里查看结果。

答案 1 :(得分:0)

该解决方案原来是另一篇文章,我们必须创建一个简单的Windows服务,该服务在与Windows 2003 R2上的应用程序池相同的帐户下运行。