名称'X509Certificate2UI'在当前上下文中不存在

Gui*_*ngo 16 c# asp.net-mvc asp.net-mvc-4

在Asp Net MVC4应用程序中使用X509Certificate2UI类是否有任何问题

using System.Security.Cryptography.X509Certificates;


private static X509Certificate2 PickCertificate(StoreLocation location, StoreName name)
{

    try
    {
        store.Open(OpenFlags.ReadOnly);
        //PROBLEM IS HERE
        X509Certificate2 cert = X509Certificate2UI.SelectFromCollection(store.Certificates, "Caption", "Message", X509SelectionFlag.SingleSelection)[0]; 
}
    catch (Exception)
    {               
        throw;
    }
}
Run Code Online (Sandbox Code Playgroud)

它抱怨当前上下文中没有'X509Certificate2UI'名称不知道,因为该类在System.Security.Cryptography.X509Certificates;

fre*_*hbm 37

您需要System.Security.dll在项目中包含引用,因为它不包含在mscorlib程序集中,而是包含在程序集中System.Security .