ASP.NET Unit Testing With Typemock Isolator

I’ve just stumbled upon this extraordinary offer. I’ve been evaluation Typemock before and it’s one of the best (if not the best) unit testing tool for SharePoint. And now its creators are launching a wide promotion campaign:

Unit Testing ASP.NET? ASP.NET unit testing has never been this easy.

Typemock is launching a new product for ASP.NET developers – the ASP.NET Bundle – and for the launch will be giving out FREE licenses to bloggers and their readers.

The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both Typemock Isolator, a unit test tool and Ivonna, the Isolator add-on for ASP.NET unit testing, for a bargain price.

Typemock Isolator is a leading .NET unit testing tool (C# and VB.NET) for many ‘hard to test’ technologies such as SharePoint, ASP.NET, MVC, WCF, WPF, Silverlight and more. Note that for unit testing Silverlight there is an open source Isolator add-on called SilverUnit.
The first 60 bloggers who will blog this text in their blog and tell us about it, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator + Ivonna). If you post this in an ASP.NET dedicated blog, you’ll get a license automatically (even if more than 60 submit) during the first week of this announcement.

Also 8 bloggers will get an additional 2 licenses (each) to give away to their readers / friends.
Go ahead, click the following link for more information on how to get your free license.

Windows Defender Update and the Page Error in Development Web Server

Another of the strange, unexplained errors with a simple (yet unexpected) cause.

SYMPTOMS

You are developing an ASP.NET Site or Web Project in Visual Studio 2005/2008. You start the Debug process. Your browser window opens with a message:

Page Load Error

or

The page cannot be found.

Additionally, you have Windows Defender installed on your machine.

THE CAUSE

A flawed update of the Windows Defender removes the localhost entries from hosts file in windowssystem32devicesetc folder.

SOLUTION

Manually add the following entries back to the hosts file:

127.0.0.1 localhost

More details: http://www.h-online.com/security/Windows-Defender-False-alarm-triggered-by-hosts-file–/news/112814

.NET Framework 3.5 SP1 and Training Update

As you might know, Microsoft has released a service pack for .NET Framework 3.5 few days ago. Let’s see what it adds to the standard framework:

  • ASP.NET Dynamic Data mechanism for quick scaffolding of the database operations
  • ADO.NET Data Service framework, with REST-based service to expose data for its consumption by web services and WCF clients
  • Entity Framework for ADO.NET, an middle-layer ORM and query mechanism that provides an abstract view of the data, detached from its physical implementation
  • Improvements to the CLR engine (mainly for permissions and performance) and other components of the framework

You can download the SP1 from here.

Also, the .NET 3.5 training kit I was referring to before has been updated to the SP1 version. You can grab it here.

Page.Trace and System.Diagnostics.Trace Comparison

More often than not, I see how newbie .NET programmers are confused when trying to trace ASP.NET applications. The origin of the confusion is that .NET Framework exposes two different tracing mechanisms when you are developing web applications.

General .NET Framework Tracing

Firstly, you have the standard low-level System.Diagnostics.Trace class. This class allows us to emit tracing information within our code, using Trace.WriteLine() methods. We also need a TraceListener, which will allow us to capture this information into a storage we choose. .NET Framework does the plumbing for us when we associate a TraceListener with an application, using its configuration file.

There are several pre-made TraceListener implementations already available, such as TextWriterTraceListener (which writes the tracing information into a text file) and EventLogTraceListener (which writes the same information in a specified event log, even if it’s in a remote computer).

ASP.NET Tracing

ASP.NET offers another tracing mechanism for web developers, based on System.Web.TraceContext class. This is an object that lives in ASP.NET page, just like Controls, Request, Response and so on. We have to enable tracing in web.config file, and we can also set it up to display the tracing information on the page itself (setting pageOutput=’true’) or using ASP.NET trace viewer (appending /Trace.axd to the page URL). For example:

<trace pageOutput="true" enabled="true"/>

You can emit tracing information from ASP.NET code using Write or Warn methods of the Page.Trace property. The difference is that Warn messages are displayed in red.

The best thing is that ASP.NET runtime adds a lot of information by default, such as:

  • timing of the main page events, so we can check how long it takes
  • page controls hierarchy tree
  • server variables
  • request and response information

in addition to our own tracing information, as displayed below:

image

Summary

We can use System.Diagnostics namespace objects to trace in ANY .NET Framework application, including ASP.NET ones. But, for ASP.NET applications, we have a powerful tracing mechanism already set in place by Page.Trace property.

More Information

.NET Tracing Walkthrough
System.Diagnostics.Trace Class
ASP.NET Tracing

How to Clear ASP.NET Web Cache

In ASP.NET you can remove an item from the web cache by invoking Cache.Remove(string ID). But, what happens when, for some reason, you want to quickly clear the whole cache? There’s no Clear or RemoveAll method in System.Web.Caching.Cache object.

WORKAROUND

You can iterate over all the entries and remove them by their key (or ID), using the GetEnumerator method of the Cache class.

IDictionaryEnumerator enumerator = Cache.GetEnumerator();

while(enumerator.MoveNext())
{
Cache.Remove(enumerator.Key)
;
}