Error: 'System.NotSupportedException' for SecurityProtocol on IIS

Last Reply on Oct 06, 2016 08:05 AM By dharmendr

Posted on Oct 06, 2016 07:17 AM

hi,

 

i have configured paypal on my server and added these lines to enabl tls requested by paypal in my application

 

but when i open the page it gives me following error

 

https://snag.gy/fh587e.jpg

what should i do  Please advice
  ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        ServicePointManager.DefaultConnectionLimit = 9999;

        //end of server protocal

        //Post back to either sandbox or live
        string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";


        //post of live
        string strLive = "https://www.paypal.com/cgi-bin/webscr";



        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
        //Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);
        string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
        strRequest += "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
        //req.Proxy = proxy;
        //Send the request to PayPal and get the response
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();

        if (strResponse == "VERIFIED")
        {
}

 

Posted on Oct 06, 2016 07:20 AM

Hi nauna,

namespace System.Net
{
    [System.Flags]
    public enum SecurityProtocolType
    {
       Ssl3 = 48,
       Tls = 192,
       Tls11 = 768,
       Tls12 = 3072,
    }
}
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 ||(SecurityProtocolType)768 || (SecurityProtocolType)3072;

Refer the below link.

http://stackoverflow.com/questions/28286086/default-securityprotocol-in-net-4-5

 


Posted on Oct 06, 2016 07:56 AM

where should i add this namespace in project? Please guide.

 

 

should i add this on my page or some where else?

 


Posted on Oct 06, 2016 08:05 AM

This namespace already present. You need to select SecurityProtocolType and press F12 you will able to see the enum. Check the availe protocoltype in the system dll and you can use those only in your code.