Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 28th, 2007, 08:05 AM
Authorized User
 
Join Date: Mar 2006
Location: Sofia, , Bulgaria.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to kalchev
Default certificate pfx c# gives me an err ".forbidden 403

Hello averyone,
I have a certificate file "cert.pfx" and I've tried to use it all those ways showed bellow in the code. All the time I recieve the err:

"{System.Net.WebException: The remote server returned an error: (403) Forbidden.
   at System.Net.HttpWebRequest.GetResponse()...}"
I've imported the certificate in all possible the Certificates in the mmc Local Computer and User and still the same. The certificate password is perfect working when I taste it with the software given me from the company I bought the service. So any help is really welcom. Here is the source (One of the idea is that migh have some diificultis in the part of handshaking or whatever they called it):

Code:
            try
            {
                HttpWebRequestC2D = (HttpWebRequest)HttpWebRequest.Create(sConnectStringUrl);
                HttpWebRequestC2D.Method = "POST";
                HttpWebRequestC2D.ContentType = "text/xml";
                //X509Certificate x509 = X509Certificate.CreateFromCertFile(sCertFileName);
                //X509Certificate x509_1 = new System.Security.Cryptography.X509Certificates.X509Certificate2(sCertFileName, @"*******");
                //X509Certificate x509_1 = new System.Security.Cryptography.X509Certificates.X509Certificate2(File.ReadAllBytes(sCertFileName), @"*********", X509KeyStorageFlags.MachineKeySet);
                X509Certificate x509_1 = new System.Security.Cryptography.X509Certificates.X509Certificate2(File.ReadAllBytes(sCertFileName), @"*******", X509KeyStorageFlags.MachineKeySet);

                X509Store storeMyUser = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                X509Store storeMachine = new X509Store(StoreLocation.LocalMachine);

                storeMyUser.Open(OpenFlags.MaxAllowed);
                storeMachine.Open(OpenFlags.MaxAllowed);

                //HttpWebRequestC2D.Headers.Add();
                X509Certificate2Collection x509CertCollectUser = storeMyUser.Certificates.Find(X509FindType.FindBySerialNumber, @"17 84 75 4f f3 74 a4 4e ae 40 d5 1b d2 bd c2 5e", false);
                X509Certificate2Collection x509CertCollectMachine = storeMachine.Certificates.Find(X509FindType.FindBySerialNumber, @"17 84 75 4f f3 74 a4 4e ae 40 d5 1b d2 bd c2 5e", false);

                HttpWebRequestC2D.ClientCertificates.Add(x509_1);
                for (int i = 0; i < x509CertCollectUser.Count;i++)
                    HttpWebRequestC2D.ClientCertificates.Add(x509CertCollectUser[i]);
                for (int i = 0; i < x509CertCollectMachine.Count; i++)
                    HttpWebRequestC2D.ClientCertificates.Add(x509CertCollectMachine[i]);

                storeMyUser.Close();
                storeMachine.Close();
                //System.Security.Cryptography.X509Certificates.
                //PFXExportCertStore();

                StreamWriter StreamWriterC2D = new StreamWriter(HttpWebRequestC2D.GetRequestStream());

                XmlTextWriter XmlTextWriterRequest = new XmlTextWriter(StreamWriterC2D);

                XmlTextWriterRequest.WriteProcessingInstruction("xml", @"version=""1.0"" encoding=""utf-8""");
                //XmlTextWriterRequest.WriteDocType("REQUEST_GROUP", null, "C2DRequestv2.0.dtd", null);


                XmlTextWriterRequest.WriteStartElement("OFX");

                XmlTextWriterRequest.WriteStartElement("SIGNONMSGSRQV1");
                XmlTextWriterRequest.WriteStartElement("SONRQ");
                XmlTextWriterRequest.WriteElementString("DTCLIENT", "20020725092657");
                XmlTextWriterRequest.WriteElementString("USERID", sUser);
                XmlTextWriterRequest.WriteElementString("USERPASS", sPassword);
                XmlTextWriterRequest.WriteElementString("LANGUAGE", "ENG");
                XmlTextWriterRequest.WriteElementString("APPID", "11111111");
                XmlTextWriterRequest.WriteElementString("APPVER", "2");
                XmlTextWriterRequest.WriteEndElement();
                XmlTextWriterRequest.WriteEndElement();

                XmlTextWriterRequest.WriteStartElement("EIVVERMSGSRQV1");
                XmlTextWriterRequest.WriteStartElement("EIVEMPLOYMENTTRNRQ");
                XmlTextWriterRequest.WriteElementString("TRNUID", "1234567890");
                XmlTextWriterRequest.WriteStartElement("TRNPURPOSE");
                XmlTextWriterRequest.WriteElementString("CODE", "PPCREDIT");
                XmlTextWriterRequest.WriteEndElement(); //TRNPURPOSE
                XmlTextWriterRequest.WriteStartElement("EIVEMPLOYMENTRQ");
                XmlTextWriterRequest.WriteElementString("EMPLOYERCODE", "99999");
                XmlTextWriterRequest.WriteElementString("EIVEMPLOYEEID", "001012414");
                XmlTextWriterRequest.WriteEndElement(); //EIVEMPLOYMENTRQ
                XmlTextWriterRequest.WriteEndElement();////EIVEMPLOYMENTTRNRQ
                XmlTextWriterRequest.WriteEndElement();////EIVVERMSGSRQV1

                XmlTextWriterRequest.WriteEndElement();//root OFX

                XmlTextWriterRequest.Close();

                HttpWebResponseC2D = (HttpWebResponse)HttpWebRequestC2D.GetResponse();


Thank You,
G
  #2 (permalink)  
Old April 21st, 2009, 07:56 AM
Registered User
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Were you able to find a solution to this problem? I'm currently working on the same project that your code is for and I'm running into the same issue.

Thanks!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB. NET HTTP/1.1 403 ACCESS FORBIDDEN spaxton111757 Classic ASP Professional 0 July 8th, 2007 08:03 AM
Security with .PFX dparsons ASP.NET 1.0 and 1.1 Professional 0 April 30th, 2007 01:53 PM
403 Forbidden page comes up rocco50 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 October 9th, 2006 11:17 AM
2003 Server 403 forbidden error mat41 Classic ASP Professional 13 August 31st, 2006 05:09 PM
error 403 forbidden cfemocha BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 May 15th, 2005 11:38 AM



All times are GMT -4. The time now is 01:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.