我们在ASP.NET应用程序中创建一个X509Certificate2对象以进行定期的传出连接。每次创建这些证书之一时,都会在以下位置创建一个新文件:
We create a X509Certificate2 object in our ASP.NET app to make periodic outgoing connections. Every time one of these certificates is created a new file is created in:
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
该文件夹现在有400万个从未清除的文件。我试图删除Persist标志
That folder now has 4 million files that never get cleaned up. I've tried removing the Persist flag
新X509Certificate2(certBytes,p12Pwd, X509KeyStorageFlags.MachineKeySet);
new X509Certificate2(certBytes, p12Pwd, X509KeyStorageFlags.MachineKeySet);
//否X509KeyStorageFlags.PersistKeySet
//no X509KeyStorageFlags.PersistKeySet
但这无济于事-每次调用仍然获得2Kb文件。
but that doesn't help -- still get the 2Kb file on every call.
当我看到这个答案,但这是一台2008 R2服务器,临时文件不是0字节,因此情况似乎有所不同。
I got my hopes up when I saw this answer, but this is a 2008 R2 server, and the temp files are not 0 bytes, so it seems to be a different case.
我们如何使用一个X509Certificate2而不填满磁盘?
How can we use a X509Certificate2 without filling up the disk?
推荐答案使用.NET 4.6 :
X509Certificate2实现了以开头的.NET的IDisposable接口。框架4.6;在.NET Framework的早期版本中,X509Certificate2类的不实现此接口,因此因此不存在Dispose方法。
X509Certificate2 implements the IDisposable interface starting with the .NET Framework 4.6; in previous versions of the .NET Framework, the X509Certificate2 class does not implement this interface, and therefore the Dispose method does not exist.
更多推荐
创建X509Certificate2时是否阻止文件创建?
发布评论