-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Pramod
Message 1 in Discussion
Hi, I am trying to implement SSL for my upload class through .NET. I have created
a console application to implement it. The code is as follows.....
using System;
using System.Web;
using System.IO;
using System.Net;
using System.Text;
using System.Configuration;
using System.Security.Cryptography.X509Certificates;
namespace ConsoleApplication3
{
/// <summary>
/// Summary description for Upload.
/// </summary>
public class Upload
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string sFileName;
sFileName = "c:\\upload.doc";
UploadFiles(sFileName);
}
public static void UploadFiles(string sFileName)
{
try
{
String uriString = "https://rpramod/WebApplicationTest/WebForm1.aspx";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// X509 certificate accepts only DER encoded certificates.
X509Certificate X509 = X509Certificate.CreateFromCertFile("c:\\rpramod.cer");
//Implement this to override the default certificate policy
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
// Send the network credentials - assign the network credentials to the webclient
object
NetworkCredential networkCredentials = new
NetworkCredential("username","password","domain");
myWebClient.Credentials = networkCredentials;
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray = myWebClient.UploadFile(uriString,"POST",sFileName);
if(responseArray.Length > 0)
Console.WriteLine("Uploading " + sFileName + " complete");
}
catch(Exception E)
{
Console.WriteLine(E.Message);
}
}
// Class which implements the ICertificatePolicy to accept the certificate
sealed class AcceptAllCertificatePolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint,
X509Certificate certificate, WebRequest request,
int certificateProblem)
{
// Just accept the certificate.
return true;
}
}
}
}
In the IIS, I have issued a server certificate, and i have exported the client
certificate in DER encoded format. I have also set the properties for the
webapplication to "Require SSL" and "Require Client Certificate" in IIS. When I run
the application, the following is the error that I get. "The remote server returned an
error (403) forbidden.". I have also checked up with the permission and it seems to be
fine. IF Anybody has any suggestions to resolve this error, please let me know.
Thanks
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]