locked
How do you establish a TLS 1.2 connection RRS feed

  • Question

  • User709978785 posted

    Can anyone please explain how to establish a TLS 1.2 connection using VB.NET? My site is on a Win 2012 R2 server and is targeting .Net 4.5.

    Where does this code get added (web.config/global.asax or other or set to use TLS 1.2

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    Monday, June 18, 2018 10:32 PM

All replies

  • User283571144 posted

    Hi Jackxxx,

    According to your description, I suggest you could add this line inside the gloal.asax file or ure it in a function, at the starting line.

    Liket this:

    Imports System.Net
    Imports System.Web.Optimization
    
    Public Class MvcApplication
        Inherits System.Web.HttpApplication
    
        Protected Sub Application_Start()
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
            AreaRegistration.RegisterAllAreas()
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters)
            RouteConfig.RegisterRoutes(RouteTable.Routes)
            BundleConfig.RegisterBundles(BundleTable.Bundles)
        End Sub
    End Class
    

    Best Regards,

    Brando

    Wednesday, June 20, 2018 6:59 AM
  • User1536599556 posted
    You may try this code:

    Public
    Shared Function processCCRequest(ByVal strRequest As String) As String 'declare the web request object and set its path to the PayTrace API Dim ThisRequest As WebRequest = WebRequest.Create("https://beta.paytrace.com/api/default.pay") 'configure web request object attributes ThisRequest.ContentType = "application/x-www-form-urlencoded" ThisRequest.Method = "POST" 'encode the request Dim Encoder As New System.Text.ASCIIEncoding Dim BytesToSend As Byte() = Encoder.GetBytes(strRequest) 'declare the text stream and send the request to PayTrace's API Dim StreamToSend As Stream = ThisRequest.GetRequestStream StreamToSend.Write(BytesToSend, 0, BytesToSend.Length) StreamToSend.Close() ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Dim TheirResponse As HttpWebResponse = ThisRequest.GetResponse Dim sr As New StreamReader(TheirResponse.GetResponseStream) Dim strResponse As String = sr.ReadToEnd sr.Close() Return strResponse End Function
    Tuesday, December 18, 2018 5:35 AM