I recently ran into this problem with multiple deployed IIS sites on the same server (Windows 2008 R2). In our environment, each site operates in different application pools, but in some cases the same identifier may be assigned to these pools.
Our application creates a key if it does not exist, and puts it in a container with a name based on the current identifier. The first deployed site always worked, but if we deployed another site to a different application pool with the same identifier, the second one failed.
It turns out that when the key is stored, Windows gives full access to the user "IIS APPPOOL \ AppPoolName", and not the identifier that we assigned to the pool.
So, our solution was to give the container explicit permissions for the current identifier (this is similar to @Webmixer answer, the only difference is in CryptoKeyAccessRule ):
CspParameters cspParams; cspParams = new CspParameters(PROVIDER_RSA_FULL); cspParams.KeyContainerName = CONTAINER_NAME; cspParams.Flags = CspProviderFlags.UseMachineKeyStore; cspParams.ProviderName = "Microsoft Strong Cryptographic Provider"; CryptoKeyAccessRule rule = new CryptoKeyAccessRule(System.Security.Principal.WindowsIdentity.GetCurrent(), CryptoKeyRights.FullControl, AccessControlType.Allow); cspParams.CryptoKeySecurity = new CryptoKeySecurity(); cspParams.CryptoKeySecurity.SetAccessRule(rule);
Steve czetty
source share