SslStream.AuthenticateAsClient Method RRS feed

  • Question

  • Target Host is one of the input parameters for AuthenticateAsClient method.

    For an application, how do we get value for TargetHost?

    I have client certificate in PKCS12 format as one input.

    Other inputs are certificate password, server IP and port number.

    Is the end user supposed to provide this value as input?


    • Edited by AmalJesudas Monday, December 2, 2019 1:44 PM
    Monday, December 2, 2019 1:43 PM


All replies

  • Hi AmalJesudas, 

    Thank you for posting here.

    ‘TargetHost’ is the name of the server that shares this ‘SslStream’. If your server has DNS name "", you can use following code:

            string serverName = "";
            TcpClient client = new TcpClient(serverName, 443);
            SslStream ssl = new SslStream(client.GetStream());

    Here’s two related references you can refer to.

    1. .NET SSLStream - AuthenticateAsClient - what is targetHost
    2. SSLStream.AuthenticateAsClient not working without server certificate name

    Hope them can help you.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, December 3, 2019 6:54 AM
  • Hi Xingyu Zhao,

    Thanks for your reply.

    Sorry for catching up late as I was busy with other work.

    As you clarified, the target name is the DNS name of the server.

    In my case, I have a client application that sends data to a remote server.

    For configuring this connection, we provide inputs like IP, port number, certificate and password through UI.

    My doubt is how to pass the target name. Which of the below method is to be followed?:

    1. Target Name will also be passed as an input through UI 
    2. Provide server certificate that contains the DNS name and obtain Target Name from the same

    Wanted to know what is the norm when using applications as most discussions are around web pages/portals.


    • Edited by AmalJesudas Friday, January 10, 2020 11:08 AM
    Friday, January 10, 2020 11:04 AM