在iis7上工作但不在本地计算机上的Web应用程序

时间:2015-01-24 20:28:12

标签: vb.net web-services ssl-certificate client-certificates

我在ISS7服务器上成功构建并编译了我的VB.NET Web应用程序,但在通过Visual studion 2013进行编译时在本地机器上它是 返回“System.Security.Cryptography.CryptographicException:系统找不到指定的文件。”错误。 不确定发生了什么,但在Dim cert As New X509Certificate2(certFile, certFilePassword,X509KeyStorageFlags.MachineKeySet)

时抛出错误

以下是我尝试使用本地计算机上安装的证书的代码。

Sub LoginED(ByVal token As String)
Try
'We need the ED user ID
lblEDUserID.Text = GetEDUserID().ToString()

'Track user login
InsertLogin(txtEDUsername.Text, True)

'Set login cookies for ED users            
If lblEDUserID.Text = "0" Then
lblEDLoginStatus.Text = "You have entered an incorrect login. Please try again."
Else

Dim certFile As String = "VIP_Cert.pfx"
Dim certFilePassword As String = "password"

Dim cert As New X509Certificate2(certFile, certFilePassword,X509KeyStorageFlags.MachineKeySet)
Dim vipSoapInterfaceQueryServiceCert As New WebReference.QueryService

'Dim fs As FileStream = File.Open(certFile, FileMode.Open, FileAccess.ReadWrite)
'Dim filesize As Long = fs.Length
'Dim buffer(filesize) As Byte
'fs.Read(buffer, 0, filesize)

'byte[] buffer = new byte[fs.Length];
'int count = fs.Read(buffer, 0, buffer.Length);
'fs.Close()

lblEDLoginStatus.Text = "Activation  "
vipSoapInterfaceQueryServiceCert.ClientCertificates.Add(cert)

Dim vipSoapInterfaceService As New WebReference.GetCredentialInfoRequestType()
vipSoapInterfaceService.credentialId = "SMR23324543"
vipSoapInterfaceService.credentialType = WebReference.CredentialTypeEnum.STANDARD_OTP
vipSoapInterfaceService.requestId = "ABCD"

Dim vipSoapInterfaceResponse As New WebReference.GetCredentialInfoResponseType()

vipSoapInterfaceResponse = vipSoapInterfaceQueryServiceCert.getCredentialInfo(vipSoapInterfaceService)
lblEDLoginStatus.Text = "WebService Response: " + vipSoapInterfaceResponse.credentialId + ", Status:" + vipSoapInterfaceResponse.credentialStatus

End If
Finally

到目前为止我尝试了什么: 1)试图指定证书文件在机器上的完整路径。

2)尝试了不同格式的证书(.pfx; .p12; .cer)

3)尝试打开证书,读取并发送到缓冲区以从缓冲区获取输入。 (我在IIS7上部署时删除了缓冲区逻辑,因为我将.pfx证书文件放在System32文件夹中,代码可以自动识别证书。但本地无法识别)

4)我尝试删除“X509KeyStorageFlags.MachineKeySet”参数。 (我用它来进行IIS7编译)

任何帮助表示赞赏!!

1 个答案:

答案 0 :(得分:0)

谢谢!我可以弄清楚需要什么。 我必须为证书创建一个应用程序池,然后为该池提供完全控制权限