<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: URL-encoded slashes in System.Uri</title>
	<link>http://grootveld.com/archives/21</link>
	<description>But I digress...</description>
	<pubDate>Wed, 07 Jan 2009 09:56:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.2</generator>

	<item>
		<title>by: Arnout</title>
		<link>http://grootveld.com/archives/21#comment-420</link>
		<pubDate>Wed, 04 Jun 2008 20:36:31 +0000</pubDate>
		<guid>http://grootveld.com/archives/21#comment-420</guid>
					<description>Sure, feel free to post this on Zaypay (be sure to include my &quot;no guarantees&quot; note, though :-). I would indeed appreciate a reference to my site. Thanks.</description>
		<content:encoded><![CDATA[<p>Sure, feel free to post this on Zaypay (be sure to include my &#8220;no guarantees&#8221; note, though :-). I would indeed appreciate a reference to my site. Thanks.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Justin</title>
		<link>http://grootveld.com/archives/21#comment-419</link>
		<pubDate>Wed, 04 Jun 2008 10:29:13 +0000</pubDate>
		<guid>http://grootveld.com/archives/21#comment-419</guid>
					<description>Thank you so much!! It works like a charm :-)
Is it okay if I post this solution on the Zaypay forum with a reference to your site?
Again, many thanks for your troubles!</description>
		<content:encoded><![CDATA[<p>Thank you so much!! It works like a charm :-)<br />
Is it okay if I post this solution on the Zaypay forum with a reference to your site?<br />
Again, many thanks for your troubles!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Arnout</title>
		<link>http://grootveld.com/archives/21#comment-418</link>
		<pubDate>Sat, 31 May 2008 13:59:59 +0000</pubDate>
		<guid>http://grootveld.com/archives/21#comment-418</guid>
					<description>Justin,

I managed to reproduce the issue on an oldish W2K3 VM. Also found it mentioned on &lt;a href='https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=288395'&gt;Microsoft Connect&lt;/a&gt;.

After some digging with Reflector, the following code seems to do the trick:

&lt;pre class='codesample'&gt;
&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;UriHacks&lt;/span&gt;
{
&amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: green;&quot;&gt;// System.UriSyntaxFlags is internal, so let's duplicate the flag privately&lt;/span&gt;
&amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; CompressPath = 0x800000;
&amp;#160;
&amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; LeaveMultipleSlashesAsIs(&lt;span style=&quot;color: #2b91af;&quot;&gt;Uri&lt;/span&gt; uri)
&amp;#160;&amp;#160;&amp;#160; {
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (uri == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; {
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;ArgumentNullException&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;uri&quot;&lt;/span&gt;);
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; }
&amp;#160;
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: #2b91af;&quot;&gt;FieldInfo&lt;/span&gt; fieldInfo = uri.GetType().GetField(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;m_Syntax&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;BindingFlags&lt;/span&gt;.Instance &amp;#124; &lt;span style=&quot;color: #2b91af;&quot;&gt;BindingFlags&lt;/span&gt;.NonPublic);
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (fieldInfo == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; {
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MissingFieldException&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;'m_Syntax' field not found&quot;&lt;/span&gt;);
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; }
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; uriParser = fieldInfo.GetValue(uri);
&amp;#160;
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; fieldInfo = &lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(&lt;span style=&quot;color: #2b91af;&quot;&gt;UriParser&lt;/span&gt;).GetField(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;m_Flags&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;BindingFlags&lt;/span&gt;.Instance &amp;#124; &lt;span style=&quot;color: #2b91af;&quot;&gt;BindingFlags&lt;/span&gt;.NonPublic);
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (fieldInfo == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; {
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;throw&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;MissingFieldException&lt;/span&gt;(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;'m_Flags' field not found&quot;&lt;/span&gt;);
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; }
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; uriSyntaxFlags = fieldInfo.GetValue(uriParser);
&amp;#160;
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; &lt;span style=&quot;color: green;&quot;&gt;// Clear the flag that we don't want&lt;/span&gt;
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; uriSyntaxFlags = (&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;)uriSyntaxFlags &amp;#38; ~CompressPath;
&amp;#160;
&amp;#160;&amp;#160;&amp;#160; &amp;#160;&amp;#160;&amp;#160; fieldInfo.SetValue(uriParser, uriSyntaxFlags);
&amp;#160;&amp;#160;&amp;#160; }
}
&lt;/pre&gt;

To use it, just construct your Uri, and then call LeaveMultipleSlashesAsIs() on it.

&lt;b&gt;NOTE:&lt;/b&gt; I didn't further investigate what exactly was changed between .NET 2.0 RTM and subsequent versions, so no guarantees that this actually works and/or doesn't have any horrible side-effects...</description>
		<content:encoded><![CDATA[<p>Justin,</p>
<p>I managed to reproduce the issue on an oldish W2K3 VM. Also found it mentioned on <a href='https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=288395'>Microsoft Connect</a>.</p>
<p>After some digging with Reflector, the following code seems to do the trick:</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&#8217;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> CompressPath = 0&#215;800000;
&nbsp;
&nbsp;&nbsp;&nbsp; <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> LeaveMultipleSlashesAsIs(<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;">&#8220;uri&#8221;</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;">&#8220;m_Syntax&#8221;</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;">&#8220;&#8216;m_Syntax&#8217; field not found&#8221;</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;">&#8220;m_Flags&#8221;</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;">&#8220;&#8216;m_Flags&#8217; field not found&#8221;</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&#8217;t want</span>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; uriSyntaxFlags = (<span style="color: blue;">int</span>)uriSyntaxFlags &amp; ~CompressPath;
&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; fieldInfo.SetValue(uriParser, uriSyntaxFlags);
&nbsp;&nbsp;&nbsp; }
}
</pre>
<p>To use it, just construct your Uri, and then call LeaveMultipleSlashesAsIs() on it.</p>
<p><b>NOTE:</b> I didn&#8217;t further investigate what exactly was changed between .NET 2.0 RTM and subsequent versions, so no guarantees that this actually works and/or doesn&#8217;t have any horrible side-effects&#8230;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Justin</title>
		<link>http://grootveld.com/archives/21#comment-417</link>
		<pubDate>Sat, 31 May 2008 11:02:47 +0000</pubDate>
		<guid>http://grootveld.com/archives/21#comment-417</guid>
					<description>Hey,

Thanks for the quick response. Sorry I forgot to say that this only happens with ASP.NET 2 and lower. And if you got an Vista or Windows machine with the latest updates than this doesn't happen (Then the slashes don't get escaped). Microsoft changed this behavior sometime ago. So on my local machine the double slashes don't get escaped, but on the server they do :(. So I need to find a way to force ASP.NET 2 to not escape these slashes.

Thanks for your trouble....</description>
		<content:encoded><![CDATA[<p>Hey,</p>
<p>Thanks for the quick response. Sorry I forgot to say that this only happens with ASP.NET 2 and lower. And if you got an Vista or Windows machine with the latest updates than this doesn&#8217;t happen (Then the slashes don&#8217;t get escaped). Microsoft changed this behavior sometime ago. So on my local machine the double slashes don&#8217;t get escaped, but on the server they do :(. So I need to find a way to force ASP.NET 2 to not escape these slashes.</p>
<p>Thanks for your trouble&#8230;.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Arnout</title>
		<link>http://grootveld.com/archives/21#comment-415</link>
		<pubDate>Thu, 29 May 2008 11:57:21 +0000</pubDate>
		<guid>http://grootveld.com/archives/21#comment-415</guid>
					<description>Justin,

I just tried your code, using &quot;https://secure.zaypay.com///pay/TestingSomething&quot; as the URL (since I don't have a key). It works fine for me &amp;#8212; using &lt;a href='http://www.fiddlertool.com'&gt;Fiddler&lt;/a&gt;, I see that all three slashes are sent in the request.

I did note that in your example, you're specifying &quot;text/html&quot; for the Accept header, instead of &quot;application/xml&quot;. In my tests this doesn't affect the result (apart from getting an HTML response from Zaypay instead of an XML one, of course), but then again, I'm using a fake URL...

Can you try your test while running Fiddler? Curious to find out what it shows in your case. (Be sure to read my latest post to &lt;a href='http://grootveld.com/archives/22'&gt;make sure HttpWebRequest and Fiddler play nicely together&lt;/a&gt;).</description>
		<content:encoded><![CDATA[<p>Justin,</p>
<p>I just tried your code, using &#8220;https://secure.zaypay.com///pay/TestingSomething&#8221; as the URL (since I don&#8217;t have a key). It works fine for me &mdash; using <a href='http://www.fiddlertool.com'>Fiddler</a>, I see that all three slashes are sent in the request.</p>
<p>I did note that in your example, you&#8217;re specifying &#8220;text/html&#8221; for the Accept header, instead of &#8220;application/xml&#8221;. In my tests this doesn&#8217;t affect the result (apart from getting an HTML response from Zaypay instead of an XML one, of course), but then again, I&#8217;m using a fake URL&#8230;</p>
<p>Can you try your test while running Fiddler? Curious to find out what it shows in your case. (Be sure to read my latest post to <a href='http://grootveld.com/archives/22'>make sure HttpWebRequest and Fiddler play nicely together</a>).
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Justin</title>
		<link>http://grootveld.com/archives/21#comment-414</link>
		<pubDate>Wed, 28 May 2008 15:29:54 +0000</pubDate>
		<guid>http://grootveld.com/archives/21#comment-414</guid>
					<description>Hey there,

I need to implement a payment method for a side i'm working at. There we need to make calls to an API with URLs like &quot;https://secure.zaypay.com///pay/price setting id/payments/payment id&quot;. Note the 3 slashes after the &quot;.com&quot;. I need to set the HTTP accept header to &quot;application/xml&quot;, and get the xml responce from that API script. For this I use a HttpWebRequest :

&lt;pre&gt;Uri link = new Uri(&quot;https://secure.zaypay.com///pay/&quot; + priceSettingId + &quot;/payments/&quot; + paymentId + &quot;?key=theKey&quot;);

System.Net.HttpWebRequest textMessageRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(link);
textMessageRequest.Method = &quot;POST&quot;;
textMessageRequest.Accept = &quot;text/html&quot;;
textMessageRequest.ContentType = &quot;application/x-www-form-urlencoded&quot;;
textMessageRequest.ContentLength = 0;&lt;/pre&gt;

Only in the URL the &quot;///&quot; get's escaped into one &quot;/&quot;. so this is not going to work and I get an File does not exists warning.

I have been searching for a solution for days now. Can you please give me a hand in a solution for my problem. I think your solution is almost what I need as wel. But i can't get it to work. How accectly can I use this, I'm not that good with reflection :-(

Many thanks in advance.....</description>
		<content:encoded><![CDATA[<p>Hey there,</p>
<p>I need to implement a payment method for a side i&#8217;m working at. There we need to make calls to an API with URLs like &#8220;https://secure.zaypay.com///pay/price setting id/payments/payment id&#8221;. Note the 3 slashes after the &#8220;.com&#8221;. I need to set the HTTP accept header to &#8220;application/xml&#8221;, and get the xml responce from that API script. For this I use a HttpWebRequest :</p>
<pre>Uri link = new Uri("https://secure.zaypay.com///pay/" + priceSettingId + "/payments/" + paymentId + "?key=theKey");

System.Net.HttpWebRequest textMessageRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(link);
textMessageRequest.Method = "POST";
textMessageRequest.Accept = "text/html";
textMessageRequest.ContentType = "application/x-www-form-urlencoded";
textMessageRequest.ContentLength = 0;</pre>
<p>Only in the URL the &#8220;///&#8221; get&#8217;s escaped into one &#8220;/&#8221;. so this is not going to work and I get an File does not exists warning.</p>
<p>I have been searching for a solution for days now. Can you please give me a hand in a solution for my problem. I think your solution is almost what I need as wel. But i can&#8217;t get it to work. How accectly can I use this, I&#8217;m not that good with reflection :-(</p>
<p>Many thanks in advance&#8230;..
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
