<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arnout's Eclectica &#187; .NET</title>
	<atom:link href="http://grootveld.com/archives/category/net/feed" rel="self" type="application/rss+xml" />
	<link>http://grootveld.com</link>
	<description>But I digress...</description>
	<lastBuildDate>Wed, 10 Feb 2010 20:00:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making HttpWebRequest work while having Fiddler decrypt SSL</title>
		<link>http://grootveld.com/archives/22/making-httpwebrequest-work-while-having-fiddler-decrypt-ssl</link>
		<comments>http://grootveld.com/archives/22/making-httpwebrequest-work-while-having-fiddler-decrypt-ssl#comments</comments>
		<pubDate>Thu, 29 May 2008 11:54:49 +0000</pubDate>
		<dc:creator>amg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Reminder]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://grootveld.com/archives/22</guid>
		<description><![CDATA[Just a quick reminder to myself, so that I can forget about it...
Fiddler can act as a man-in-the-middle and decrypt SSL traffic, but then System.Net.Security rightfully complains about an invalid remote certificate ("The remote certificate is invalid according to the validation procedure."). This results in a System.Net.WebException "The underlying connection was closed: Could not establish [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick reminder to myself, so that I can forget about it...</p>
<p><a href='http://www.fiddlertool.com'>Fiddler</a> can act as a man-in-the-middle and decrypt SSL traffic, but then System.Net.Security rightfully complains about an invalid remote certificate ("The remote certificate is invalid according to the validation procedure."). This results in a System.Net.WebException "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.".</p>
<p>To prevent this from happening:</p>
<pre class="codesample">
<span style="color: #2b91af;">ServicePointManager</span>.ServerCertificateValidationCallback = <span style="color: blue;">delegate</span> { <span style="color: blue;">return</span> <span style="color: blue;">true</span>; };
</pre>
<p>Just be sure to not include this in production code :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://grootveld.com/archives/22/making-httpwebrequest-work-while-having-fiddler-decrypt-ssl/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>URL-encoded slashes in System.Uri</title>
		<link>http://grootveld.com/archives/21/url-encoded-slashes-in-systemuri</link>
		<comments>http://grootveld.com/archives/21/url-encoded-slashes-in-systemuri#comments</comments>
		<pubDate>Wed, 30 Apr 2008 21:11:18 +0000</pubDate>
		<dc:creator>amg</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://grootveld.com/archives/21</guid>
		<description><![CDATA[Two weeks ago, an ex-colleague asked me to take a look at a problem that he and his team had encountered. They tried using a System.Uri with URL-encoded slashes, but those slashes kept ending up unencoded in the resulting URI:

Uri uri = new Uri("http://somesite/media/http%3A%2F%2Fsomesite%2Fimage.gif");
Console.WriteLine(uri.AbsoluteUri);
// Output: http://somesite/media/http%3A//somesite%2Fimage.gif

That's a totally different URL, which the target server refuses [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago, an ex-colleague asked me to take a look at a problem that he and his team had encountered. They tried using a <code>System.Uri</code> with URL-encoded slashes, but those slashes kept ending up unencoded in the resulting URI:</p>
<pre class='codesample'>
<span style="color: #2b91af;">Uri</span> uri = <span style="color: blue;">new</span> <span style="color: #2b91af;">Uri</span>(<span style="color: #a31515;">"http://somesite/media/http%3A%2F%2Fsomesite%2Fimage.gif"</span>);
<span style="color: #2b91af;">Console</span>.WriteLine(uri.AbsoluteUri);
<span style="color: green;">// Output: <b>http://somesite/media/http%3A<span style='border: #c0c0f7 1px solid;'>//</span>somesite%2Fimage.gif</b></span>
</pre>
<p>That's a totally different URL, which the target server refuses to process.</p>
<p>I was sure that they must have overlooked something, and that there would be some way to tell the Uri constructor to leave all encoded characters as-is. But no, it does not seem possible; dots and slashes are always decoded. I find that quite surprising, so if anyone can point me to an official solution, I'd be much obliged.</p>
<p>In the mean time, a reflection-based hack, courtesy of <a href='http://www.aisto.com/roeder/dotnet/' title="Lutz Roeder's .NET Reflector">Reflector</a> and the <a href='http://weblogs.asp.net/scottgu/archive/2008/01/16/net-framework-library-source-code-now-available.aspx' title="ScottGu's post about the .NET Framework Library Source Code">.NET Reference Source</a>:</p>
<pre class='codesample'>
<span style="color: blue;">static</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">UriHacks</span>
{
&nbsp;&nbsp;&nbsp; <span style="color: green;">// System.UriSyntaxFlags is internal, so let's duplicate the flag privately</span>
&nbsp;&nbsp;&nbsp; <span style="color: blue;">private</span> <span style="color: blue;">const</span> <span style="color: blue;">int</span> UnEscapeDotsAndSlashes = 0x2000000;
&nbsp;
&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> LeaveDotsAndSlashesEscaped(<span style="color: blue;">this</span> <span style="color: #2b91af;">Uri</span> uri)
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (uri == <span style="color: blue;">null</span>)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">ArgumentNullException</span>(<span style="color: #a31515;">"uri"</span>);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: #2b91af;">FieldInfo</span> fieldInfo = uri.GetType().GetField(<span style="color: #a31515;">"m_Syntax"</span>, <span style="color: #2b91af;">BindingFlags</span>.Instance | <span style="color: #2b91af;">BindingFlags</span>.NonPublic);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (fieldInfo == <span style="color: blue;">null</span>)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">MissingFieldException</span>(<span style="color: #a31515;">"'m_Syntax' field not found"</span>);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">object</span> uriParser = fieldInfo.GetValue(uri);
&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fieldInfo = <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">UriParser</span>).GetField(<span style="color: #a31515;">"m_Flags"</span>, <span style="color: #2b91af;">BindingFlags</span>.Instance | <span style="color: #2b91af;">BindingFlags</span>.NonPublic);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">if</span> (fieldInfo == <span style="color: blue;">null</span>)
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">MissingFieldException</span>(<span style="color: #a31515;">"'m_Flags' field not found"</span>);
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue;">object</span> uriSyntaxFlags = fieldInfo.GetValue(uriParser);
&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">// Clear the flag that we don't want</span>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; uriSyntaxFlags = (<span style="color: blue;">int</span>)uriSyntaxFlags &amp; ~UnEscapeDotsAndSlashes;
&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fieldInfo.SetValue(uriParser, uriSyntaxFlags);
&nbsp;&nbsp;&nbsp; }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://grootveld.com/archives/21/url-encoded-slashes-in-systemuri/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
