<?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>entwicklungsgedanken &#187; Exception</title>
	<atom:link href="http://www.entwicklungsgedanken.de/tag/exception/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entwicklungsgedanken.de</link>
	<description>Verschiedene Gedanken rund um die Softwareentwicklung</description>
	<lastBuildDate>Mon, 09 Jan 2012 14:47:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Redirect from the OnException-method inside the controller with ASP.Net MVC</title>
		<link>http://www.entwicklungsgedanken.de/2009/07/16/redirect-from-the-onexception-method-inside-the-controller-with-asp-net-mvc/</link>
		<comments>http://www.entwicklungsgedanken.de/2009/07/16/redirect-from-the-onexception-method-inside-the-controller-with-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 08:42:00 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[HandleError]]></category>
		<category><![CDATA[OnException]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=290</guid>
		<description><![CDATA[If your controller uses the HandleError-Attribute it handles exceptions thrown by action methods. I wanted to catch these exceptions and redirect to a custom error page. A simple RedirectToAction inside the OnException method does not work. But the ExceptionContext is all we need. #region Error handling protected override void OnException&#40;ExceptionContext filterContext&#41; &#123; // Make use [...]]]></description>
			<content:encoded><![CDATA[<p>If your controller uses the <code>HandleError</code>-Attribute</code> it handles exceptions thrown by action methods. I wanted to catch these exceptions and redirect to a custom error page. A simple <code>RedirectToAction</code> inside the <code>OnException</code> method does not work. But the <code>ExceptionContext</code> is all we need.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080;">#region Error handling</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnException<span style="color: #008000;">&#40;</span>ExceptionContext filterContext<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
 <span style="color: #008080; font-style: italic;">// Make use of the exception later</span>
 <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Session</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ErrorException&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Exception</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">// Mark exception as handled</span>
 filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">ExceptionHandled</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">// ... logging, etc</span>
&nbsp;
 <span style="color: #008080; font-style: italic;">// Redirect</span>
 filterContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Result</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RedirectToAction</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Error&quot;</span>, <span style="color: #666666;">&quot;Home&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
 <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnException</span><span style="color: #008000;">&#40;</span>filterContext<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #008080;">#endregion</span></pre></div></div>

<p>It stored the exception thrown inside the action onto the session. So this information is available inside my "error-action".</p>
<p>My custom "error-action" even allows me to distinguish between normal requests and Ajax-requests (where I use a partial-view instead of a normal view) to display a nicer error message to the end-user.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2009/07/16/redirect-from-the-onexception-method-inside-the-controller-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Problems with the ContentByQueryWebPart (CQWP) and its ItemXslLink-property</title>
		<link>http://www.entwicklungsgedanken.de/2008/04/08/problems-with-the-contentbyquerywebpart-cqwp-and-its-itemxsllink-property/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/04/08/problems-with-the-contentbyquerywebpart-cqwp-and-its-itemxsllink-property/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 19:12:59 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[cqwp]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[HttpContext]]></category>
		<category><![CDATA[XslItemLink]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=41</guid>
		<description><![CDATA[If you ever tried to set the ItemXslLink (which is a normal property of the ContentByQueryWebPart) you will see that sometimes this simply doesn&#8217;t work. You get an exception! Object reference not set to an instance of an object Why? The CmsDataFormWebpart.MakeSiteRelativeUrl (which is called somewhere when setting this property) needs the HttpContext.Current which isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever tried to set the <code>ItemXslLink</code> (which is a normal property of the <code>ContentByQueryWebPart</code>) you will see that sometimes this simply doesn&#8217;t work. You get an exception!</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">Object</span> reference not set to an instance of an <span style="color: #6666cc; font-weight: bold;">object</span></pre></div></div>

<h4>Why?</h4>
<p>The <code>CmsDataFormWebpart.MakeSiteRelativeUrl</code> (which is called somewhere when setting this property) needs the <code>HttpContext.Current</code> which isn&#8217;t available when using a <strong>console application</strong> or inside an <strong>event receiver</strong> (<a href="http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/">déjà vu!</a>).</p>
<h3>Solution</h3>
<p>Inside the <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3123533&#038;SiteID=1">MSDN-Forums</a> a user named <em>AlexUC</em> found a good workaround.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">==</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    HttpRequest request <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HttpRequest <span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&quot;</span>, web<span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span>, <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HttpContext <span style="color: #008000;">&#40;</span>request, <span style="color: #008000;">new</span> HttpResponse <span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> StringWriter <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;HttpHandlerSPWeb&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> web<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>
Perhaps this even works when one is inside an asynchronous-event inside an event receiver?! Perhaps one can redirect the user inside the <code>ItemAdded</code>-Method?!<br />
<strong>I will analyze this soon&#8230;</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/04/08/problems-with-the-contentbyquerywebpart-cqwp-and-its-itemxsllink-property/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

