求指点,, System.InvalidOperationException: 当前会话不是交互式会话。
这是一个证书相关的网站,我在程序中调试没有问题,但是等我发布了就出现这个错误,已经确定错误在下面的范围内、、、string userName = this.Session["userName"].ToString().Trim();//获取用户名
string path1 = MyCA.BLL.Cert.GetCertByName(userName)["certUrl"].ToString().Trim();//获取服务器所存当前用户的在服务器的虚拟路径证书路径。
string path2 = Request.Url.ToString();
string certpath = path2.Replace("Check/checkcert.aspx", "");
certpath += path1.Remove(0, 2);//获取当前证书在服务器的URI
Uri url = new Uri(certpath);
WebClient myWebClient = new WebClient();
byte[] sercert = myWebClient.DownloadData(url);//获取从服务器的到的当前用户证书的数据流
X509Certificate2 servercert = new X509Certificate2(sercert);//从服务器得到的当前用户证书
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
X509Certificate2Collection sc = X509Certificate2UI.SelectFromCollection(fcollection, "请选择证书", "请选择", X509SelectionFlag.SingleSelection);//用户选择证书对话框
X509Certificate2 sub1 = sc[0];
当前会话不是交互式会话。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: 当前会话不是交互式会话。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[InvalidOperationException: 当前会话不是交互式会话。]
System.Security.Cryptography.CAPI.CryptUIDlgSelectCertificateW(CRYPTUI_SELECTCERTIFICATE_STRUCTW csc) +208514
System.Security.Cryptography.X509Certificates.X509Certificate2UI.SelectFromStore(SafeCertStoreHandle safeSourceStoreHandle, String title, String message, X509SelectionFlag selectionFlags, IntPtr hwndParent) +263
System.Security.Cryptography.X509Certificates.X509Certificate2UI.SelectFromCollectionHelper(X509Certificate2Collection certificates, String title, String message, X509SelectionFlag selectionFlag, IntPtr hwndParent) +122
System.Security.Cryptography.X509Certificates.X509Certificate2UI.SelectFromCollection(X509Certificate2Collection certificates, String title, String message, X509SelectionFlag selectionFlag) +38
Check_checkcert.Page_Load(Object sender, EventArgs e) +424
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
--------------------编程问答-------------------- 没人么?
补充:.NET技术 , ASP.NET