ASP.NET Ajax Error/Exception Handling – the simple way
A lot has been said about error/exception handling with ASP.NET Ajax pages, more specifically, how to properly handle and display error messages inside an UpdatePanel. For instance, Scott Gu wrote this sometime ago:
You can now optionally [...] intercept any error message sent back from the server, and perform custom client-side actions as a result [...]. (source)
Well, I disagree with “optionally”. As far as I understand, if you don’t explicitly intercept the error/exception sent back from the server from within an UpdatePanel, your user will get an unfriendly javascript error like this:
So what can you do to fix this? Easy, just add this piece of Javascript code to your Masterpage (or to any page if you don’t have/use a Masterpage):
<%-- This script must be placed after the form declaration (i.e. <form id="form1" runat="server">) --%>
<script type="text/javascript">
Sys.Application.add_load(AppLoad);
function AppLoad() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
}
function EndRequest(sender, args) {
// Check to see if there's an error on this request.
if (args.get_error() != undefined) {
var msg = args.get_error().message.replace("Sys.WebForms.PageRequestManagerServerErrorException: ", "");
// Show the custom error.
// Here you can be creative and do whatever you want
// with the exception (i.e. call a modalpopup and show
// a nicer error window). I will simply use 'alert'
alert(msg);
// Let the framework know that the error is handled,
// so it doesn't throw the JavaScript alert.
args.set_errorHandled(true);
}
}
</script>
Now you should get error messages like this (javascript alert): 
This is exactly how exceptions used to be displayed when thrown inside an UpdatePanel before .NET 3.5.
Note: I do understand the benefits of a the new approach. It gives you flexibility to present the error message any way you want, before your hands where quite tied to this simple Javascript alert window.
As a matter of fact, I’ve implemented a nice ModalPopup and have ensure that only user-friendly messages are actually shown: only messages of a certain type (i.e. UIMessageException) are forwarded to the user without any cleanup/transformation.
References:
- Exception handling best practices in ASP.NET web applications
- How Do I: Customize Error Handling for the ASP.NET AJAX UpdatePanel
- MVP blog: UpdatePanel: having fun with errors
- MSDN post (be careful, not 100% correct): Customizing Error Handling for ASP.NET UpdatePanel Controls
Cheers!
Tip/Trick: How to Show Active File in Solution Explorer (Visual Studio 2008)
Many thanks to “Ronald Widha” by blogging about this Visual Studio simple trick that allows you to show the active files in Visual Studio (one little feature that I use a lot when working with Eclipse):
One of the most annoying thing about Visual Studio default settings is the fact that the Solution Explorer doesn’t track what files you are currently looking at. Alot of developers thought this was the only way, and had to bear the pain of flicking through the Solution Explorer while scratching their head to figure out ‘where the hell I put this file?’.
There is actually a setting in Visual Studio that does this automatically.
Tools – Options – Projects and Solutions – Track Active Item in Solution Explorer
There is actually a setting in Visual Studio that does this automatically.Tools – Options – Projects and Solutions – Track Active Item in Solution ExplorerJust tick the box..and you’re all set!Just tick the box..and you’re all set!
source: http://www.ronaldwidha.net/2008/11/26/visual-studio-show-active-file-in-solution-explorer/
Thanks Ronald!
Optimizing Ubuntu Linux to minimize possible SSD problems
Here are other tips on optimizing your Ubuntu Linux to minimize possible SSD problems. I still have some concerns about SSD stuttering and limited life-span, but I hope that following the instructions below I will minimize these problems:
- Using noatime and nodiratime
UUID=da949f54-f6a5-4dd3-a293-8b2925834baf / ext4 noatime,nodiratime,errors=remount-ro0 1
- Setting up ramdisk on heavily used temp folder:
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /media/ramdisk tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/run tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/lock tmpfs defaults,noatime,mode=1777 0 0
- Changing I/O Schedule to “deadline”
Source: http://www.ocztechnologyforum.com/forum/showthread.php?t=54379
So far, no problems.
Tip/Trick: How to Download Youtube songs to MP3
I recently was searching for a service that would allow me to download the song of a youtube video without downloading or installing any software… So that’s when I found a service from Zamzar that not only allows you to download the video or simply the song, but it allows you to convert a lot of other stuff, including PDFs: http://www.zamzar.com/
ASP.NET Development server slow on Windows Vista/7 with Firefox or Chrome
While developing an ASP.NET website running it on the Visual Studio ASP.NET development server I was noticing that page loads exceedingly slowly in Firefox and Google Chrome after upgrading to Windows 7 (same issue occurs with Windows Vista).
A page refresh would usually take up to 3 seconds (localhost) even without changing the source code (so it should be instantaneously, especially now that I’m using a SSD).
It appears that there is some kind of bug on Vista/Windows 7 with DSN and IPv6, but that can be easily fixed. Here are some of the solutions I have found:
1. Recommended Solution – machine wide: uncomment the localhost address in the hosts file (%WINDIR%\System32\drivers\etc\hosts): (source)
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
# ::1 localhost
# localhost name resolution is handled within DNS itself.127.0.0.1 localhost# ::1 localhost
2. Firefox-only solution: disable IPv6
1. Type about:config in the address bar and press Enter.
2. Scroll down until you find network.dns.disableIPv6.
3. Double-click on it to change its value to true.
4. Restart Firefox.
3. System wide-configuration (option 1): Disable IPv6 Random identifier
netsh interface tcp set global autotuninglevel=disabled
4. System wide-configuration (option 2): Disable IPv6 from Your LAN Interfaces and Connections
1. Launch Vista, click on Start, and then click on Run. Once the Run window appears, type regedit.
2. Once you have accessed the registry, you will add a registry value as follows: (DWORD type) Set to OxFF.
3. The registry is as follows: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\DisabledComponents
iTunes on Ubuntu? Forget! Use Songbird instead!
Can I run iTunes in Ubuntu (or Linux in general)?
No, you can’t. Really? Well, you could try to run it with wine… But if you check the latest releases, it’s really not supported… I tried various configurations, wine 1, wine-1.2, iTunes 8.x, iTunes 9.x… Nothing worked! If you really have enough patience to figure out all of the “fix-me” messages in the wine log, good luck!
Ok, so what can I use instead? What is out there that that truly replaces iTunes?
Well, you will be really surprised by a project called Songbird (www.getsongbird.com). Check this out:

Screenshot of Songbird 1.2
It’s sleek, easy to use and can be customized by tons of plugins…
Installation Instructions for Ubuntu Linux (and similar flavours):
Unfortunately Songbird is not yet available under the “Ubuntu Software Center” or thru Synaptic/Apt-get, so you have basically two options:
- Download the latest .tar.gz file from the main website (www.getsongbird.com), manually unzip and run the executable file, or,
- (Recommended Solution): Use this installer (.deb) created by Eric: http://skyzim.com/songbird-1-2-0-installer/
The installation works like a charm, it even creates the proper menu entry under Application -> Sound & Video. Thanks Eric!
Welcome to the Songbird community!
First impressions: Solid State Drive (SSD) vs 7500 rpm HDD
So, my first impressions on SSD? It’s damn fast! Let me say that again, IT’S DAMN FAST!
Seriously, I’m talking about at least 10x faster… Check it out:
- Boot time on Ubuntu 9.10 (disregarding BIOS initial checkup time)
- 7500 rpm HDD: ~160 sec
- OCZ Solid Series 60GB SSD: ~20 sec; (what?! yes, your read correctly)
- Copying Files (ex: typical video of 600 MB)
- Before, with a “fast” 7500 rpm HDD: a lot… no need to mention, it was pretty lame…
- OCZ SSD: 12 seconds!
- Firefox Browsing / Overall Impression:
- Opening tabs, clicking back and other things are now instantaneous with SSD.
Check out this vid to see a guy doing a boot time test on a Ubuntu with SSD: Booting Ubuntu 9 04 with SSD
Even if you’re on a budget,you can start with the entry-level OCZ Solid Series…
Nowadays you can get one for less than $150 bucks… Here is where I got mine:
Based on some Internet reviews I thought this one would be too slow compared to the other options (i.e. Vertex), but It’s like comparing a Porsche 911 to a Bugatti Veyron, both are extremely faster than my Honda Civic
Happy shopping!
Speeding up build times in ASP.NET with RamDisk
Here is another quick tip on how to speed up build times on your ASP.NET website projects: create a ram-based drive (i.e. using RamDisk) and change your default “Temporary ASP.NET Files” to this memory-based drive.
Then every time you change your ASP.NET pages (or any code-behind or reference DLLs) the build will happen much faster because is doing all in memory.
So, how you do this? Simply follow these steps:
1) Make sure you have enough free memory:
Open the usual apps you use (i.e. Visual Studio, Outlook, etc) and check how much free memory you have (Task Manager -> Performance -> Physical Memory -> Available).
So, let’s say you have 500MB free and your total memory physical memory is 2GB (Task Manager -> Performance -> Physical Memory -> Total). The total I’d recommend allocating for your virtual drive would be half of your free memory, or 250MB.
If you’re short on free memory, try running some cleanup tools like TuneUp Utilities (very good, but paid) or CCleaner (free). Besides that, you can always check what services are running and stop/disable the ones you really don’t need (this is a delicate step, be careful not to stop essential services – use Google to find out what’s essential and what’s not).
2) Install RamDisk
I’m using a free implementation that can be found here. You can follow these steps for a details explanation of this tool and installation instructions.
Make sure you install it and create a drive letter (i.e. “R:”) with the disk size amount calculated in the previous step. If you over-allocate it, your Windows will run out of memory and the whole purpose of this idea will be worthless.
3) Change your default “Temporary ASP.NET Files” folder to your new ram-based drive
Here you have two options. You can do this only for a specific site or for all projects running on your computer. If you have too many sites you may run out of disk space in your ramdisk, so choose your option wisely
3.1) Configuration for a specific website (local settings):
Change your site’s web.config “compilation” property to specify the new path. Below is an example that assumes “R:\ASP_NET_TempFiles\” as the new ram-based folder location:
<system.web>
....
<compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
....
</compilation>
....
</system.web>
3.2) Configuration for all ASP.net websites (global settings):
To implement this globally all you need to do is change your global web.config (which is usually located somewhere like this C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config)and adjust the compilation properties the same way the local settings (previous example):
<system.web>
....
<compilation debug="true" tempDirectory="R:\ASP_NET_TempFiles\">
....
</compilation>
....
</system.web>
And your done!
Two last tips I can give you is to keep an eye on the usage of your ramdisk folder. If it get’s full, you’ll have to manually delete some old temporary files. The second tip is to watch how your free memory, if it gets too close to it’s total it might indicate the you either have too much programs running or you might have to reduce your ramdisk size.
Happy speed building!
Tip/Trick: Optimizing ASP.NET Build Time with Dynamic Compilation (optimizeCompilations=”true”)
If you are experiencing slow builds with ASP.NET projects or want to learn how to speed them up please read on.
Microsoft has introduced a new optimizeCompilations switch in ASP.NET that can greatly improve the compilation speed in some scenarios. You can read this blog post to understand the overall idea, study a more detailed explanation about Dynamic Compilation here or simply follow these 2 easy steps:
1) Install this hot-fix:
- Windows XP: http://code.msdn.microsoft.com/KB969612
- Windows Vista: http://code.msdn.microsoft.com/KB967535
- Windows 7 – not necessary
2) Update your web.config as follows:
Add optimizeCompilations=”true” to your <compilation …> tag. Below is an example:
<system.web>
....
<compilation debug="true" optimizeCompilations="true">
....
</compilation>
....
</system.web>
And you’re done! Next time you change something inside the App_code or even a dll inside the bin folder you might not have to wait the entire site to rebuild.
Important note: this approach speeds things up but you might get some weird errors when you start changing some code signatures or restructuring dlls.In this case, all you need to do is a simple “rebuild project/solution” inside your Visual Studio to get things straight again.
Yet Another Budgeting System – YABS
Yet Another Budgeting System (http://code.google.com/p/yabs-online/) is a web-based ajax-enabled application with the intent to provide a simple yet complete solution to manage my personal home finances. It borrows budgeting concepts of a great product I use and recommend called ‘You Need A Budget’ (YNAB). See more details at: http://www.youneedabudget.com
However, the real motivation behind this project is to keep me updated with latest trends in the Java/J2EE world. There are countless interesting Java frameworks and tools, but for this project I’ve picked the following winning set: JSF, Facelets, RichFaces, Spring and Hibernate!
So, this project does not have real schedules or documented requirements. It’s a fun and open project that is always there for me, just waiting to be updated the latest trends in java development!
By the way, the current technologies in place for this version are:
- JSF 1.2 / Apache MyFaces 1.2.3
- Facelets 1.1.14
- RichFaces 3.2.1
- Spring Framework 2.5.5
- Hibernate 3
- HSQLDB 1.8.0
- JUnit 4.4
If you have any questions or would like to participate, just leave a comment here.

