Hi,
I am Eswaran.R and I am a stranger to the Connection with SSL in Asp.Net.I hope you will answer to my problem as soon as possible. If it means i shall be happy.
I have a Webform that is going to send data to the secure site (like https://123abc.wep_as.asp that is working within intranet)
-
when I clik the button that is gong to send the data to the secure site using the SSL Connection in WebForm.aspx.cs.
-
I tried lot but i had error when I published that in Testing server. It gave me error called “The underlying connetion was closed. Could not establish a trusted with SSL/TLS with the secure channel”.
-
I don't know why it happens.
-
I have checked whethere proper certificate has installed in Testing server. It installed.
-
I show my coding here.
class file name is “CertPolicy.cs”
public class CertPolicy : ICertificatePolicy {
public enum eCertificateProblem {
CertNone = 0,
CertEXPIRED = 1, //0x800B0101,
CertVALIDITYPERIODNESTING = 2, //0x800B0102,
CertROLE = 3, //0x800B0103,
CertPATHLENCONST = 4 //0x800B0104,
}
public CertPolicy() { }
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
{
eCertificateProblem cp = (eCertificateProblem) certificateProblem;
switch (cp)
{
case (eCertificateProblem.CertUNTRUSTEDROOT):
return true;
case eCertificateProblem.CertCN_NO_MATCH:
return true;
case eCertificateProblem.CertNone:
return true;
}
return false;
}
}
and my button click event is going to call this funcation
protected string sendDATA()
{
ServicePointManager.CertificatePolicy = new CertPolicy();
ServicePointManager.MaxServicePoints = 4;
ServicePointManager.MaxServicePointIdleTime = 1000;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
ServicePointManager.Expect100Continue = false;
try
{
strXML = "Hai"; //Sample data to send
WebRequest req = null;
WebResponse rps = null;
string strUrlToSecureSite = ConfigurationManager.AppSettings["urlToSecureSite"].ToString();
req = WebRequest.Create(strUrlToSecureSite); //like (https://123abc.12sd.asp)
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
this.TxRequest.Value = strXML; //TxRequest is a Hidden Field
StreamWriter wr = new StreamWriter(req.GetRequestStream());
wr.WriteLine(TxRequest.Value.ToString());
wr.WriteLine(TxRequest);
wr.Close();
rps = req.GetResponse();
if (!req.Equals(null))
{
req.GetRequestStream().Close();
}
if (!rps.Equals(null))
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(strUrlToTravelers);
httpWebRequest.KeepAlive = false;
HttpWebResponse httpWebResponse = (HttpWebResponse)(httpWebRequest.GetResponse());
}
Stream receiveStream = rps.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader(receiveStream, encode);
TxRequest.Value = readStream.ReadToEnd();
readStream.Close();
rps.Close();
}
catch (WebException e)
{
Response.Write(e.Message.ToString());
}
return TxRequest.Value.ToString();
}If anyone help this that would be better for me.
Thanks
R. Eswaran Radharkishnan