<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/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>Security</title><link>http://forums.asp.net/25.aspx</link><description>All about ASP.NET security (authentication, authorization, membership, roles, etc.) and the Login controls. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=24&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Receive "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." when using HttpWebRequest &amp; HttpWebResponse objects</title><link>http://forums.asp.net/thread/1984255.aspx</link><pubDate>Thu, 01 Nov 2007 02:36:42 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1984255</guid><dc:creator>XiaoYong Dai – MSFT</dc:creator><author>XiaoYong Dai – MSFT</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1984255.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1984255</wfw:commentRss><description>&lt;p&gt;Hi&lt;/p&gt;A possible cause is that&amp;nbsp;the name in the HTTP request does not always exactly match the name for the server certificate, which results in the SSL challenge and response. To work-around this, you can implement Certificate Policy, and have it accept the certificate, so particular client could&amp;nbsp;connect to this server. 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Receive "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." when using HttpWebRequest &amp; HttpWebResponse objects</title><link>http://forums.asp.net/thread/1983236.aspx</link><pubDate>Wed, 31 Oct 2007 14:37:17 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1983236</guid><dc:creator>atconway</dc:creator><author>atconway</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1983236.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1983236</wfw:commentRss><description>&lt;p&gt;Thank you for the response, I will research both of the links.&amp;nbsp; Do you have any idea though why it works some of the time and other times it does not with the code I currently have?&lt;/p&gt;</description></item><item><title>Re: Receive "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." when using HttpWebRequest &amp; HttpWebResponse objects</title><link>http://forums.asp.net/thread/1975243.aspx</link><pubDate>Fri, 26 Oct 2007 06:30:51 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1975243</guid><dc:creator>XiaoYong Dai – MSFT</dc:creator><author>XiaoYong Dai – MSFT</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1975243.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1975243</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;atconway:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt; 
&lt;p&gt;System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---&amp;gt; System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It seems that site&amp;#39;s certificate is rejected by the .NET framework&amp;#39;s default CertificatePolicy.&amp;nbsp;Here we&amp;nbsp;can find some of&amp;nbsp;best possible reasons why this happen, One workround is specify a custom certificate policy (less secure one) like this.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://developers.de/blogs/damir_dobric/archive/2006/06/29/585.aspx"&gt;&lt;font color="#034efa"&gt;http://developers.de/blogs/damir_dobric/archive/2006/06/29/585.aspx&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx"&gt;&lt;font color="#034efa"&gt;http://msdn2.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;&lt;a class="" name="四分大是大非"&gt;&lt;/a&gt;&lt;span style="FONT-SIZE:7.5pt;COLOR:#999999;FONT-FAMILY:Verdana;"&gt;This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.&lt;/span&gt;&lt;span style="COLOR:#999999;"&gt;&lt;/span&gt;</description></item><item><title>Receive "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel." when using HttpWebRequest &amp; HttpWebResponse objects</title><link>http://forums.asp.net/thread/1972251.aspx</link><pubDate>Wed, 24 Oct 2007 19:44:37 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1972251</guid><dc:creator>atconway</dc:creator><author>atconway</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1972251.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1972251</wfw:commentRss><description>&lt;p&gt;I am having an issue with some code that does a HttpWebRequest to get a response back from a URL.&amp;nbsp; The code &lt;em&gt;does &lt;/em&gt;work... some times.&amp;nbsp; Most of the time is gets the response back just fine.&amp;nbsp; But on occasion I get the following error:&lt;/p&gt;
&lt;p&gt;System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---&amp;gt; System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.&lt;/p&gt;
&lt;p&gt;Any ideas?? I had read something about setting the HttpWebRequest&amp;#39;s &amp;#39;KeepAlive&amp;#39; property to False, which I did, but it has not permanently solved the problem.&lt;/p&gt;
&lt;p&gt;Here is the code:&lt;/p&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Create an HttpWebRequest object setting the URL to post&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; request &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; HttpWebRequest = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;CType&lt;/font&gt;&lt;font size="2"&gt;(WebRequest.Create(&lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;https://www.test.com/ws/blahblahblah&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;), HttpWebRequest)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Set the &amp;#39;Method&amp;#39; property of the &amp;#39;Webrequest&amp;#39; to &amp;#39;POST&amp;#39;.&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;request.Method = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;POST&amp;quot;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Create a new string with information to POST data to the Url.&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; postData &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;String&lt;/font&gt;&lt;font size="2"&gt; = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;id=&amp;quot;&lt;/font&gt;&lt;font size="2"&gt; &amp;amp; Trim(ID) &amp;amp; &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;&amp;amp;sid=&amp;quot;&lt;/font&gt;&lt;font size="2"&gt; &amp;amp; Trim(SID)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Store data in a byte array using ASCII standard&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; byte1 &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Byte&lt;/font&gt;&lt;font size="2"&gt;() = Encoding.ASCII.GetBytes(postData)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Set the content type of the data being posted.&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;request.ContentType = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Set the content length of the string being posted.&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;request.ContentLength = byte1.Length&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Setting KeepAlive = false results in sending a Connection: Close header to the server.&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;request.KeepAlive = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;False&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Send the request;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;When using the POST method, you must get the request stream, write the data to be posted, and close the stream. &lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; newStream &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; Stream = request.GetRequestStream()&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;newStream.Write(byte1, 0, byte1.Length)&lt;/p&gt;
&lt;p&gt;newStream.Close()&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Get the HTTP response, casting to a type of HttpWebResponse&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; response &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; HttpWebResponse = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;CType&lt;/font&gt;&lt;font size="2"&gt;(request.GetResponse(), HttpWebResponse)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Load the HTTP response into a StreamReader object&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; sr &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;New&lt;/font&gt;&lt;font size="2"&gt; StreamReader(response.GetResponseStream, UTF8)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Read the stream returned from the response object&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; HTMLResponse &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;String&lt;/font&gt;&lt;font size="2"&gt; = Trim(sr.ReadToEnd())&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Based on the response, define the boolean variable dictating if the user is valid&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;If&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;CStr&lt;/font&gt;&lt;font size="2"&gt;(Replace(HTMLResponse, vbCrLf, &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;)) = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Y&amp;quot;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Then&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;User = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;True&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Else&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;User = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;False&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;End&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;If&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;Close the response object and StreamWriter (IMPORTANT)&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;response.Close()&lt;/p&gt;
&lt;p&gt;sr.Close()&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>