Error on EWP while hosting

Last post 05-01-2008 1:20 PM by Bugsy99. 7 replies.

Sort Posts:

  • Error on EWP while hosting

    12-05-2007, 1:25 AM
    • Loading...
    • dipumedayil
    • Joined on 06-01-2007, 1:58 PM
    • Posts 4
    I've implemented EWP on PayPal using the .Net 2.0 framework and X509 certificates, On my local system everything works well.
     
    On the hosting server I'm getting this error:
     

    The system cannot find the file specified.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
     
    [CryptographicException: The system cannot find the file specified.
    ]
    System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) +33
    System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
    System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) +228
    System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags) +130
    MyDom.ButtonEncryption.LoadSignerCredential(String signerPfxCertPath, String signerPfxCertPassword) in C:\Data\InetPub\wwwroot\MyDom\Basket\ButtonEncryption.cs:68
    MyDom.EWPServices.EncryptButton(String buttonParams, HttpServerUtility Server) in C:\Data\InetPub\wwwroot\MyDom\Basket\EWPServices.cs:101

    [Exception: The system cannot find the file specified.
    ]
     

    and the stack trace shows that the error is on the line:

    	_signerCert =new X509.X509Certificate2(signerPfxCertPath, signerPfxCertPassword);
    

     I can read all the files using  StreamReader.

     

    Can any one please help me???
     

  • Re: Error on EWP while hosting

    12-16-2007, 10:30 AM
    • Loading...
    • alivemedia
    • Joined on 06-21-2006, 9:34 PM
    • Posts 40

     Did you ever find a solution for this? 

    I am having the exact same problem, I'll post back if I find a solution.

  • Re: Error on EWP while hosting

    12-18-2007, 8:04 AM

    I've found the following relevant blogpost here:

    http://www.eggheadcafe.com/aspnet_answers/NETsecurity/Mar2006/post26409120.asp

     also some people suggest that this is an issue caused by the asp.net process running with medium trust on servers so it cannot access the machine certificate store. The following fix may be relevant to the problem:

    http://support.microsoft.com/kb/915980/en-us

     I have not found any solution (not involving runinc calc.exe) yet. Please do post if you find one.

    Fear is the mind-killer.
  • Re: Error on EWP while hosting

    12-18-2007, 9:08 AM

    I've found a solution that at least for now seems to work. So as it seems asp.net usually (on hosting providers?) runs with medium trust. Medium trust happens to forbid the user to access the local user store which is the default. So we have to use the Machine Store which Medium trust happens to allow. Also according to some sources local store is also fucked up when using impersonation. Further more the certificate somehow uses a certificate store even if it is not installed there and you load it from file or byte array. And now the moment you've all been waiting for - the code:

    X509Certificate2 certificate = new X509Certificate2("filename", "password", X509KeyStorageFlags.MachineKeySet);

     Just use the MachineKeySet flag. This also works with other constructors as they all have X509KeyStorageFlags overloads.

     I hope this helps some other poor soul. I straggled for days until I found this solution and said a lot of bad words about microsoft, IIS, my hosting provider, administration and security... and I would do it again :)

    if this has helped you please post here I would be very happy to know I've saved someone from what I've been through.

     P.S. My explaination as to why things work that way may be complete crap. Still the code should work.

    Fear is the mind-killer.
  • Re: Error on EWP while hosting

    12-18-2007, 12:12 PM
    • Loading...
    • alivemedia
    • Joined on 06-21-2006, 9:34 PM
    • Posts 40

    OMG - thank you!

    I think I tried every other combination for the X509KeyStorageFlags attribute except that one in all of my futal head banging attempts to get this to work.

     p.s. I could care less about if your explanation is crap or not - I have no idea I am just glad you figured it out! Big Smile

  • Re: Error on EWP while hosting

    02-28-2008, 7:09 AM
    • Loading...
    • dekartsoft
    • Joined on 11-21-2007, 7:08 AM
    • Posts 41

     OOOOOO yeahh, Thank You, Thank You, Thank You Big Smile. This worked perfectly for me.

  • Re: Error on EWP while hosting

    02-28-2008, 9:34 AM

    I am glad people are finding this:)

    Fear is the mind-killer.
  • Re: Error on EWP while hosting

    05-01-2008, 1:20 PM
    • Loading...
    • Bugsy99
    • Joined on 05-01-2008, 1:18 PM
    • Posts 1
    Worked first time!

    You're a star!

Page 1 of 1 (8 items)