Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Using Secure Sockets Layer

The System.Net classes use the Secure Sockets Layer (SSL) to encrypt the connection for several network protocols.

For http connections, the WebRequest and WebResponse classes use SSL to communicate with web hosts that support SSL. The decision to use SSL is made by the WebRequest class, based on the URI it is given. If the URI begins with "https:", SSL is used; if the URI begins with "http:", an unencrypted connection is used.

To use SSL with File Transfer Protocol (FTP), set the EnableSsl property to true prior to calling GetResponse(). Similarly, to use SSL with Simple Mail Transport Protocol (SMTP), set the EnableSsl property to true prior to sending the e-mail.

The SslStream class provides a stream-based abstraction for SSL, and offers many ways to configure the SSL handshake.

Code

String MyURI = "https://www.contoso.com/";
WebRequest WReq = WebRequest.Create(MyURI);

String serverUri = "ftp://ftp.contoso.com/file.txt"
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
request.EnableSsl = true;
request.Method = WebRequestMethods.Ftp.DeleteFile;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();

This example requires:

  • References to the System.Net namespace.

Community Additions

ADD
Show:
© 2015 Microsoft