<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tips &amp; Tricks for ASP.NET, IIS, and Visual Web Developer : remote connection</title><link>http://blogs.msdn.com/webdevelopertips/archive/tags/remote+connection/default.aspx</link><description>Tags: remote connection</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Tip #41: Did you know... establishing a remote connection to a IIS server with self-issued certificate will require a certificate validation delegate?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2009/01/04/tip-41-did-you-know-establishing-a-remote-connection-to-a-iis-server-with-self-issued-certificate-will-require-a-certificate-validation-delegate.aspx</link><pubDate>Mon, 05 Jan 2009 01:07:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9273735</guid><dc:creator>WebDevTools</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/webdevelopertips/comments/9273735.aspx</comments><wfw:commentRss>http://blogs.msdn.com/webdevelopertips/commentrss.aspx?PostID=9273735</wfw:commentRss><description>&lt;p&gt;Either through WMSvc or through your own script, whenever you try to establish a connection with a remote server, which doesn&amp;#8217;t provide a trusted certificate you need to provide a delegate for this certificate validation check to validate untrusted certificates.&lt;/p&gt;  &lt;p&gt;The signature for this delegate is as follows &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Namespace:&lt;/strong&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.security.aspx"&gt;System.Net.Security&lt;/a&gt;     &lt;br /&gt;&lt;strong&gt;Assembly:&lt;/strong&gt;&amp;#160; System (in System.dll)&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; RemoteCertificateValidationCallback(
    Object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors
)&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Thus, to accept ALL server certificates, you will need to set the callback of ServicePointManager to validate a server certificate in the following manner:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; height: 228px; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallbackFlag;

&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; RemoteCertificateValidationCallbackCheck(
    Object sender,
    X509Certificate certificate,
    X509Chain chain,
    SslPolicyErrors sslPolicyErrors
)
{
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;For the official MSDN documentation on this delegate refer to &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.security.remotecertificatevalidationcallback.aspx" target="_blank"&gt;RemoteCertificateValidationCallback Delegate&lt;/a&gt;&lt;strong&gt;&amp;#160;&lt;/strong&gt;and &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx" target="_blank"&gt;ServicePointManager.ServerCertificateValidationCallback Property&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kateryna Rohonyan 
    &lt;br /&gt;&lt;/strong&gt;SDET, &lt;a href="http://www.iis.net/"&gt;IIS Team&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9273735" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/remote+connection/default.aspx">remote connection</category></item></channel></rss>