<?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>Just a Coder &#187; HTTP</title>
	<atom:link href="http://www.nickfitz.co.uk/categories/web-development/web-standards/http/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nickfitz.co.uk</link>
	<description>The occasional online observations of Nick Fitzsimons</description>
	<lastBuildDate>Sun, 08 Jan 2012 02:09:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>More On ASP.NET&#8217;s Broken Error Handling</title>
		<link>http://www.nickfitz.co.uk/2008/12/10/more-on-aspnets-broken-error-handling/</link>
		<comments>http://www.nickfitz.co.uk/2008/12/10/more-on-aspnets-broken-error-handling/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:09:59 +0000</pubDate>
		<dc:creator>nickfitz</dc:creator>
				<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Common sense]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://www.nickfitz.co.uk/2008/12/10/more-on-aspnets-broken-error-handling/</guid>
		<description><![CDATA[More on ASP.NET's peculiar approach to HTTP errors.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve looked a bit more into <a href="http://www.nickfitz.co.uk/2008/12/07/why-cant-microsoft-just-use-http-like-everybody-else/">the way ASP.NET handles HTTP errors</a>, and frankly it now seems not just irritating, but downright bizarre.<br />
<span id="more-33"></span><br />
By the way, although the original post was about a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5">5xx series server error</a>, this also applies to <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4">4xx series client errors</a>. We&#8217;ll take the familiar <code>404 Not Found</code> as an example case.</p>
<p>Here are the main parts (with some headers and the body omitted) of the response to a broken request for <a href="http://blogs.msdn.com/oldnewthing/default.aspx">Raymond Chen&#8217;s blog</a> &#8211; I deliberately misspelled &#8220;default&#8221; as &#8220;defult&#8221; to trigger a 404:</p>
<p>
<pre><code>
HTTP/1.1 <strong>302 Found</strong>
Date: Wed, 10 Dec 2008 17:46:51 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
CommunityServer: 2.1.61025.2
<strong>Location: /error-notfound.aspx?aspxerrorpath=/oldnewthing/defult.aspx</strong>
Content-Type: text/html; charset=utf-8
Content-Length: 176
</code></pre>
</p>
<p>So, a request for something that is not found returns <code>302 Found</code>. Nice.</p>
<p>What happens when the browser follows the redirection to <code>/error-notfound.aspx?aspxerrorpath=/oldnewthing/defult.aspx</code>? This happens:</p>
<p>
<pre><code>
HTTP/1.1 <strong>404 Not Found</strong>
Date: Wed, 10 Dec 2008 17:46:52 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
CommunityServer: 2.1.61025.2
Content-Type: text/html; charset=utf-8
Content-Length: 11769
</code></pre>
</p>
<p>So, just to get this straight: when something is not found, ASP.NET returns a <code>302 Found</code> response redirecting the client elsewhere. Then, when the redirect is followed, it returns a <code>404 Not Found</code> response, despite the fact that this page clearly <em>has</em> been found, and it was the page that redirected us here that was <em>not</em> found.</p>
<p>Weird. Just plain weird.</p>
<p>Update: an online acquaintance (I don&#8217;t have a URL for him) has pointed me to a page on <cite><abbr title="Microsoft Developer Network">MSDN</abbr></cite> where <a href="http://msdn.microsoft.com/en-us/library/aa479319.aspx">the rationale for this behaviour</a> is presented:</p>
<blockquote cite="http://msdn.microsoft.com/en-us/library/aa479319.aspx"><p>
Redirect creates a new Context, Transfer does not. Redirect requires a round-trip to the browser, Transfer does not. As a result of this round-trip, Redirect rewrites the URL to reflect the location of the error page, Transfer does not.</p>
<p>
If this seems to be an argument in favor of Transfer, it isn&#8217;t. The rationale of the ASP.NET development team is that Redirect <em>accurately displays the URL of the custom error page</em>&#8230;
</p>
</blockquote>
<p>However, at no point is it explained <em>why</em> displaying such an implementation detail to clients is preferable. Given that the article starts with the words:</p>
<blockquote cite="http://msdn.microsoft.com/en-us/library/aa479319.aspx"><p>The quality of a site should be measured not only by how well it works, but by how gracefully it fails.</p>
</blockquote>
<p>it seems strange that it then recommends a technique which causes sites to fail in a singularly graceless manner.</p>
<p>My suggestion would be to modify your ASP.NET application configurations so that the <code>customError</code> capability uses the <code>Transfer</code> technique instead of <code>Redirect</code>. If that </p>
<blockquote><p>&#8230;breaks a tenet of the design philosophy of ASP.NET&#8230;</p>
</blockquote>
<p> then so be it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickfitz.co.uk/2008/12/10/more-on-aspnets-broken-error-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Can&#8217;t Microsoft Just Use HTTP Like Everybody Else?</title>
		<link>http://www.nickfitz.co.uk/2008/12/07/why-cant-microsoft-just-use-http-like-everybody-else/</link>
		<comments>http://www.nickfitz.co.uk/2008/12/07/why-cant-microsoft-just-use-http-like-everybody-else/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 05:57:39 +0000</pubDate>
		<dc:creator>nickfitz</dc:creator>
				<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Common sense]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Standards]]></category>

		<guid isPermaLink="false">http://www.nickfitz.co.uk/2008/12/07/why-cant-microsoft-just-use-http-like-everybody-else/</guid>
		<description><![CDATA[A 5xx server error shouldn't redirect the user to a new location. They should be left where they are, ready to retry when the server has recovered.]]></description>
			<content:encoded><![CDATA[<p>A few moments ago I was following a link from Google to Raymond Chen&#8217;s excellent MSDN blog <a href="http://blogs.msdn.com/oldnewthing/default.aspx">The Old New Thing</a>. As has happened to me before, I ended up getting redirected to an ASP.NET error page at a totally different URL, telling me that the site was &#8220;unable to service my request.&#8221;<br />
<span id="more-32"></span><br />
Now, the inability to serve the requested page is fair enough; Raymond has previously mentioned that the <code>blogs.msdn.com</code> site can be slow or overloaded because it comes under such relentless attack from comment spammers.</p>
<p>But a redirect to the absolute URL of an error page? That&#8217;s just annoying. It means that I can&#8217;t try to reload the page to see if the server has recovered from whatever issues are affecting it &#8211; or, more accurately, I can try to reload, but as I&#8217;m now at the absolute URL of the error page, I just keep reloading that.</p>
<p>Unsurprisingly, the HTTP 1.1 standard has already provided for this kind of situation by means of the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.4"><code>503 Service Unavailable</code></a> status code:</p>
<blockquote><p>The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay.</p>
</blockquote>
<p>If the <code>blogs.msdn.com</code> people (who, by the way, Raymond is not responsible for) would use this status code to serve their error page for the post on Raymond&#8217;s blog, I could simply come back after a few minutes and try to reload the page, as my browser would still be at the same location. </p>
<p>It&#8217;s also possible that they <em>do</em> send this status code, but with a <code>Location: </code> header to cause the redirect. (The server seems to be back on its feet again now, so I can&#8217;t inspect the HTTP cycle to check.)</p>
<p>Either way, what they do is wrong and broken. <strong>Don&#8217;t</strong> send people somewhere else to explain a <code>5xx Server Error</code> status; simply serve the explanation directly using the appropriate 5xx status code, leaving your visitors ready to try a reload when the server has recovered. Otherwise, you&#8217;ll serve a lot of <code>200 OK</code> responses from your error page, most of them to people who haven&#8217;t noticed that their location bar now points there as they hit <code>[Control | Command]-R</code> in the hope of seeing what they originally came for.</p>
<p>Note: A more recent post <a href="http://www.nickfitz.co.uk/2008/12/10/more-on-aspnets-broken-error-handling/">examines this aspect of ASP.NET in greater depth</a>, and suggests the use of a configuration option that resolves the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nickfitz.co.uk/2008/12/07/why-cant-microsoft-just-use-http-like-everybody-else/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

