<?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>Ivan Zlatev &#187; ASP.NET</title>
	<atom:link href="http://ivanz.com/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://ivanz.com</link>
	<description></description>
	<lastBuildDate>Sun, 22 Apr 2012 18:15:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>ASP.NET MVC Magical Error Logging with ELMAH</title>
		<link>http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/</link>
		<comments>http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/#comments</comments>
		<pubDate>Sun, 08 May 2011 19:09:05 +0000</pubDate>
		<dc:creator>Ivan Zlatev</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://ivanz.com/?p=749</guid>
		<description><![CDATA[<a href="http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/" title="ASP.NET MVC Magical Error Logging with ELMAH"></a>If you aren&#8217;t using ELMAH (Error Logging Modules and Handlers) you should be - http://code.google.com/p/elmah/ It&#8217;s the best thing since sliced bread for logging ASP.NET errors with practically zero effort. It basically plugs into the ASP.NET pipeline and logs all unhandled exceptions thrown and &#8230;<p class="read-more"><a href="http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/" title="ASP.NET MVC Magical Error Logging with ELMAH"></a><p>If you aren&#8217;t using ELMAH (Error Logging Modules and Handlers) you should be - <a href="http://code.google.com/p/elmah/">http://code.google.com/p/elmah/</a> It&#8217;s the best thing since sliced bread for logging ASP.NET errors with practically zero effort. It basically plugs into the ASP.NET pipeline and logs all unhandled exceptions thrown and HTTP error codes together with all sorts of other useful information such as request url, stacktrace, current user username, cookies and more. You can say it makes a snapshot of the Yellow Screen of Death with extra information. It then gives you a simple web access to the recent errors logged (by default at http//mysite.com/elmah.axd), exposing a RSS feed as well. It&#8217;s fully configurable (error filters, multiple backend log storage systems support, etc) and also can be set up to send emails on error.</p>
<p>Some screenshots:</p>
<div class="wp-caption aligncenter" style="width: 310px"><a href="http://ivanz.com/wp-content/uploads/2011/05/elmah-log-1.png" rel="shadowbox[sbpost-749];player=img;"><img title="elmah-log-1" src="http://ivanz.com/wp-content/uploads/2011/05/elmah-log-1-300x43.png" alt="" width="300" height="43" /></a><p class="wp-caption-text">List of Errors using the Web Interface</p></div>
<div class="wp-caption aligncenter" style="width: 310px"><a href="http://ivanz.com/wp-content/uploads/2011/05/elmah-log-2.png" rel="shadowbox[sbpost-749];player=img;"><img title="elmah-log-2" src="http://ivanz.com/wp-content/uploads/2011/05/elmah-log-2-300x186.png" alt="" width="300" height="186" /></a><p class="wp-caption-text">Error Details in the web interface</p></div>
<p><a href="http://ivanz.com/wp-content/uploads/2011/05/elmah-log-1.png" rel="shadowbox[sbpost-749];player=img;"></a></p>
<p>You can pull ELMAH through nuget via the &#8220;Elmah&#8221; package., which will download it and add a reference. The steps to get it all set up for ASP.NET MVC are as follows.</p>
<p>1. Register Elmah configuration sections in the <em>Web.config</em></p>
<pre class="brush: xml; title: ; notranslate">    &lt;sectionGroup name=&quot;elmah&quot;&gt;
      &lt;section name=&quot;security&quot; requirePermission=&quot;false&quot; type=&quot;Elmah.SecuritySectionHandler, Elmah&quot; /&gt;
      &lt;section name=&quot;errorLog&quot; requirePermission=&quot;false&quot; type=&quot;Elmah.ErrorLogSectionHandler, Elmah&quot; /&gt;
      &lt;section name=&quot;errorMail&quot; requirePermission=&quot;false&quot; type=&quot;Elmah.ErrorMailSectionHandler, Elmah&quot; /&gt;
      &lt;section name=&quot;errorFilter&quot; requirePermission=&quot;false&quot; type=&quot;Elmah.ErrorFilterSectionHandler, Elmah&quot; /&gt;
    &lt;/sectionGroup&gt;</pre>
<p>2. Add the root level ELMAH section in <em>Web.config</em> to tell it where to store the logs and how. Easiest to set up is to have a directory where it stores xml file for each error, <strong>but make sure the IIS process/AppPool has write access to that directory!</strong> Also I have added a filter to ignore all HTTP 404 errors. Note that this filter won&#8217;t work for ASP.NET MVC and I will come back to that later.</p>
<pre class="brush: xml; title: ; notranslate">&lt;elmah&gt;
    &lt;security allowRemoteAccess=&quot;1&quot; /&gt;
    &lt;errorLog type=&quot;Elmah.XmlFileErrorLog, Elmah&quot; logPath=&quot;~/App_Data/ElmahLogs&quot; /&gt;
    &lt;errorFilter&gt;
      &lt;test&gt;
        &lt;equal binding=&quot;HttpStatusCode&quot; value=&quot;404&quot; type=&quot;Int32&quot; /&gt;
      &lt;/test&gt;
    &lt;/errorFilter&gt;
  &lt;/elmah&gt;</pre>
<p>3. Register ELMAH with the ASP.NET pipeline <strong>both</strong> in the <strong>system.web </strong>section (when running locally) and the  <strong>system.webServer</strong> section when deployed to IIS. Just copy paste the below snippet in both sections. Notice how the default configuration says that ELMAH will be available at mysite.com/elmah.axd . You can change that if you want (in both places!)</p>
<pre class="brush: xml; title: ; notranslate">    &lt;httpModules&gt;
      &lt;add name=&quot;ErrorLog&quot; type=&quot;Elmah.ErrorLogModule, Elmah&quot; /&gt;
    &lt;/httpModules&gt;
    &lt;httpHandlers&gt;
      &lt;add verb=&quot;POST,GET,HEAD&quot; path=&quot;elmah.axd&quot; type=&quot;Elmah.ErrorLogPageFactory, Elmah&quot; /&gt;
    &lt;/httpHandlers&gt;</pre>
<p>You are done and elmah will be available at http://mysite.com/elmah.axd , but it won&#8217;t work quite right with ASP.NET MVC, because of the way errors are handled there, so there are those additional things that need to be set up:</p>
<p>4. Log exceptions before ASP.NET MVC swallows them if using customErrors or some other code handles and swallows the error. To do this I&#8217;ve implemented the below exception filter that logs all handled exceptions. It&#8217;s a good example also of how to programatically log errors with ELMAH:</p>
<pre class="brush: csharp; title: ; notranslate">using System;
using System.Web.Mvc;
using Elmah;

namespace Triply.Extensions
{
	public class ElmahHandledErrorLoggerFilter : IExceptionFilter
	{
		public void OnException (ExceptionContext context)
		{
			// Long only handled exceptions, because all other will be caught by ELMAH anyway.
			if (context.ExceptionHandled)
				ErrorSignal.FromCurrentContext().Raise(context.Exception);
		}
	}
}</pre>
<p>To register it add it in <em>Global.asax.cs</em>. The ordering is important &#8211; <strong>add it before the HandleErrorAttribute is registered</strong>.</p>
<pre class="brush: csharp; title: ; notranslate">public static void RegisterGlobalFilters (GlobalFilterCollection filters)
{
	filters.Add(new ElmahHandledErrorLoggerFilter());
	filters.Add(new HandleErrorAttribute());
}</pre>
<p>5. One final note regarding filtering out HTTP 404 errors. In ASP.NET MVC they are raised as exceptions so if you want to ignore them unfortunately you can&#8217;t do that declaratively in the Web.config. Instead you have to add the following elmah hooks to your <em>Global.asax.cs</em> to do it programatically:</p>
<pre class="brush: csharp; title: ; notranslate">		// ELMAH Filtering
		protected void ErrorLog_Filtering (object sender, ExceptionFilterEventArgs e)
		{
			FilterError404(e);
		}

		protected void ErrorMail_Filtering (object sender, ExceptionFilterEventArgs e)
		{
			FilterError404(e);
		}

		// Dismiss 404 errors for ELMAH
		private void FilterError404 (ExceptionFilterEventArgs e)
		{
			if (e.Exception.GetBaseException() is HttpException) {
				HttpException ex = (HttpException)e.Exception.GetBaseException();
				if (ex.GetHttpCode() == 404)
					e.Dismiss();
			}
		}</pre>
<p>That&#8217;s it. Now you get super cool logging (and remember &#8211; RSS feed!)</p>
<p><a href="http://ivanz.com/wp-content/uploads/2011/05/elmah-log-1.png" rel="shadowbox[sbpost-749];player=img;"><br />
</a></p>
 <img src="http://ivanz.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=749" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://ivanz.com/2011/05/08/asp-net-mvc-magical-error-logging-with-elmah/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2008 jQuery IntelliSense Fix</title>
		<link>http://ivanz.com/2009/07/01/visual-studio-2008-jquery-intellisense-fix/</link>
		<comments>http://ivanz.com/2009/07/01/visual-studio-2008-jquery-intellisense-fix/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 21:25:16 +0000</pubDate>
		<dc:creator>Ivan Zlatev</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://i-nz.net/?p=592</guid>
		<description><![CDATA[<a href="http://ivanz.com/2009/07/01/visual-studio-2008-jquery-intellisense-fix/" title="Visual Studio 2008 jQuery IntelliSense Fix"></a>I am tinkering with ASP.NET MVC and jQuery and making my first baby steps in a whole new horrible world of web development. I found out that the JavaScript IntelliSense in Visual Studio 2008 is broken out of the box. &#8230;<p class="read-more"><a href="http://ivanz.com/2009/07/01/visual-studio-2008-jquery-intellisense-fix/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://ivanz.com/2009/07/01/visual-studio-2008-jquery-intellisense-fix/" title="Visual Studio 2008 jQuery IntelliSense Fix"></a><p>I am tinkering with ASP.NET MVC and jQuery and making my first baby steps in a whole new horrible world of web development. I found out that the JavaScript IntelliSense in Visual Studio 2008 is broken out of the box. The error is:</p>
<pre>Warning    2    Error updating JScript IntelliSense: jquery-1.3.2.js:
   Object doesn't support this property or method @ 2173:1</pre>
<p>The fix for Visual Studio 2008 SP1 by Microsoft can be found here:</p>
<p><a href="http://code.msdn.microsoft.com/KB958502">KB958502 &#8211; JScript Editor support for “-vsdoc.js” IntelliSense doc. files</a></p>
 <img src="http://ivanz.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=592" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://ivanz.com/2009/07/01/visual-studio-2008-jquery-intellisense-fix/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

