Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I get Cryptography_CSP_NoPrivateKey when using IIS but not when using VS development server?
    text
    copied!<p>I'm doing a web application that utilizes an external web service. This external web service requires me to sign each of my requests. So I'm using <code>WebServicesClientProtocol</code> class and .NET 2.0 by first consuming the external web service and then manually edit the <code>Reference.cs</code> file and change the extended class from <code>System.Web.Services.Protocols.SoapHttpClientProtocol</code> to <code>Microsoft.Web.Services2.WebServicesClientProtocol</code>. Then in the <code>Page_Load</code> method I have the following code:</p> <pre><code>try { // Create the ws endpoint var uriServiceAddress = new Uri("urn:something-wse:something_NNNN"); var uribuilderViaRouter = new UriBuilder("http://xx.xxx.xx/SrvXXX_NNNN/Test.asmx"); var endpointReference = new EndpointReference(uriServiceAddress, uribuilderViaRouter.Uri); // Create the ws client var client = (WebServicesClientProtocol) new Test.Something(); client.Destination = endpointReference; // Read the certificate from MyStore on LocalMachine X509CertificateStore localStore = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore); X509SecurityToken securityToken = null; if (!localStore.OpenRead()) throw new Exception("Unable to open localstore for read"); X509CertificateCollection certificateCollection = localStore.FindCertificateBySubjectString("email@subject.test"); if (certificateCollection.Count == 0) throw new Exception("Unable to obtain security token."); securityToken = new X509SecurityToken(certificateCollection[0]); localStore.Close(); // Attach the security toekn to the client request client.RequestSoapContext.Security.Tokens.Add(securityToken); client.RequestSoapContext.Security.Elements.Add(new MessageSignature(securityToken)); // Set the timeouts client.RequestSoapContext.Security.Timestamp.TtlInSeconds = 2 * 60; client.Timeout = 60 * 10 * 1000; // 10 mínútur ættu að duga í flest. // Call the test function DataSet set = ((Test.Something)client).searchMethod("Parameter 1", "Parameter 2"); Label1.Text = User.Identity.Name+ " worked! " + set.Tables.Count + " tables!"; } catch (Exception exc) { Label1.Text = User.Identity.Name + " exception: " + exc.ToString(); } </code></pre> <p>This works fine when I run this using the Visual Studio Development Server but when I change to IIS it stops working and I get the ugly <code>Cryptography_CSP_NoPrivateKey</code> exception.</p> <p><strong>1)</strong> I have already read the Certificate properly into LocalMachine/MyStore using MMC and then I change the private key permissions using WSE 2.0 SP3 so that Everyone has full access to it. You can see this from here:</p> <p><a href="http://www1.ruedenet.is/files/CertError1.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError1.png</a></p> <p><strong>2)</strong> I also set the property so that the Visual Studio Development Server is used when I debug the application:</p> <p><a href="http://www1.ruedenet.is/files/CertError2.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError2.png</a></p> <p><strong>3)</strong> Then I run it and get a nice result:</p> <p><a href="http://www1.ruedenet.is/files/CertError3.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError3.png</a></p> <p><strong>4)</strong> However, when I change the property to use IIS (and have VS create the Virtual Directory) like this:</p> <p><a href="http://www1.ruedenet.is/files/CertError4.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError4.png</a></p> <p><strong>5)</strong> I also change the authentication method in IIS so that I get logged on (no reason for this really):</p> <p><a href="http://www1.ruedenet.is/files/CertError5.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError5.png</a></p> <p><strong>6)</strong> So I get asked for a windows logon:</p> <p><a href="http://www1.ruedenet.is/files/CertError6.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError6.png</a></p> <p><strong>7)</strong> And then my page runs and produces the error:</p> <p><a href="http://www1.ruedenet.is/files/CertError7.png" rel="nofollow noreferrer">alt text http://www1.ruedenet.is/files/CertError7.png</a></p> <p>If you could help me with this I would surely appreciate it. I have already spent hours on it and I don't want to spend more time if I'm making a fundamental error that you guys can see. BTW: I'm developing using Visual Studio 2008 on Windows Server 2008 with UAC turned off :-)</p> <p>Really looking forward to hearing from you guys. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload