Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...

Sunday, September 25

Forms Authentication in ASP.NET 2.0

An easy way to work with forms authentication in ASP.NET 2.0 is to use ASP.NET Membership and ASP.NET Login controls. ASP.NET Membership provides a way to store and manage user information and includes methods to authenticate users. ASP.NET Login Controls work with ASP.NET Membership and encapsulate the logic required to prompt users for credentials, validate users, recover or replace passwords, ...

How to ...
  • Set Authentication in web.config
    Create an authentication element under System.Web and set its mode attribute to Forms.

    The default- and login-page will be created later on. DefaultUrl returns the configured or default URL for the page to return after the request has been successfully authenticated. LoginUrl returns the configured or default URL for the Login page. This matches the loginUrl configuration attribute.
  • Set Authorization in web.config
    Create an authorization element under System.Web and set its attributes.

    Only users that belong to the Administrator-role are allowed. All other users will not have access. You can also set this info (authentication and authorization) in the ASP.NET Web Site Administration Tool.
  • Create Login.aspx
    When users request any page from the Web site and if they have not previously been authenticated, they are redirected to a page named Login.aspx. This file name has already been specified earlier in the Web.config file (loginUrl).

    To create this page, I've used the Login Control (ASP.NET 2.0). It takes input from the user and validates the username and password entered, confirms authentication or denies it. If authentication was successful, the user will be redirected to the default URL (default.aspx).
  • Create Default.aspx
    Create a webpage with info that can only be accessed after authentication of the user.
  • Configure database to store information for ASP.NET application services [Membership]
    I won't explain this into detail. More info about this in a previous post and at
  • Create new user and assign Aministrator-role to user
    The Web Site Administration Tool will help you to do this ...

After these steps, you can launch your web-application and you will be redirected to the login.aspx-page where the user-information has to be entered. After authentication you will be taken to the default.aspx-page.

If you wanted this functionality in ASP.NET 1.x you had to write a lot of code. All this functionality is now available with the new ASP.NET 2.0 Login Controls.

Tuesday, September 20

Shortcuts in the Run Window

I have copied and renamed a few Windows Applications in the system32-folder to use these one-letter-shortcuts in the Run Window.
  • Notepad.exe : n.exe
  • Mspaint.exe : p.exe
  • Cmd.exe : c.exe
  • Mmc.exe : m.exe
  • regedt32.exe : r.exe
  • ...
Sure you can find some more! Open Run Window (shortcut Windows-key + R), type n, press enter and Notepad will appear! As I often use the Run Window to start applications, it will save me a lot of typing. Being lazy is so cool ;-)

Monday, September 19

Windows Vista - Activation period has expired

I must have installed Windows Vista (beta 1 - Build 5112) a month ago : dual boot with Windows XP Pro.

When I now try to boot Windows Vista I immediately get a Windows Activation window, notifying me that the activation period has expired. Two options are presented : activating Windows Vista online or retyping the product key.

Retyping the product key [fetched from MSDN Subscription site] apparently doesn't work : Windows Activation error (error code 80072EE7 - Server name or address could not be resolved). On-line registration also doesn't work ...

Anyone a solution for this or should I wait for the next Vista CTP?

Attendees of PDC 2005 got a PDC build (5219), but there are also problems with activation.

Microsoft will normally bring out each month a monthly CTP :

The company announced that the first Windows Vista CTP build will be distributed to all PDC attendees, as well as to participants in the Windows Vista technical beta program and to Microsoft Developer Network (MSDN) and Microsoft TechNet subscribers. Microsoft will continue to release CTP builds on a monthly basis throughout the Windows Vista development process, and all feedback will be processed through the MSDN Product Feedback Center.

Thursday, September 15

Formatting : Zero / Digit placeholder

0 and # are format characters to create custom numeric format strings.

Example :

         double myDouble = 33.945;


         Console.WriteLine(myDouble.ToString("#.0000")); //Output = 33.9450

         Console.WriteLine(myDouble.ToString("#.####")); //Output = 33.945


         Console.WriteLine(myDouble.ToString("000")); //Output = 034

         Console.WriteLine(myDouble.ToString("###")); //Output = 34

The overloaded ToString-method converts the double to its equivalent string representation, using the specified format.
  • Zero placeholder [0]
    In the first example the zero placeholders after the comma make sure that there are 4 digits printed in the output. Example 3 shows padding at the other side.
  • Digit placeholder [#]
    This specifier never displays the '0' character if no significant digit is in place (no padding). See example 2 and 4.
You can also use the format string to display other objects (for example a DateTime).

         DateTime dt = DateTime.Now;

         Console.WriteLine(dt.ToString("dddd d MMMM yyyy"));

Interesting links for standard/custom formatting :

Tuesday, September 13

NUnit Test Methods

Did you know?

For backwards compatibility with previous versions of NUnit a test method will also be found if the first 4 letters are "test" regardless of case.
[TestAttribute (NUnit 2.0)]

I found out by accident. In my TestFixture-class I had a private method testDoSomething and I was surprised to see that this method was showing up in the list of test methods.

Result :

Backward compatibility for a private method?

I thought that UnitTests could only be red (failure) or green (success) ...

Monday, September 12

Managing my feeds

I had already a free subscription (Web Edition) to Newsgator Online Services for 7/8 months, but last week I switched to the Business Standard plan.

Actually I was quite happy about the free subscription because I could read my feeds from everywhere (only a browser required) and they were kept synchronized. In short : my feeds followed me wherever I was so I didn't have to read the same content over and over again on different computers. Great, but that's not all ...

Why did I make the switch to another (paying) subscription?
  • Now I can integrate my feeds into Outlook (Outlook Edition)
  • Now I get notified of new posts
  • Now I can make use of FeedDemon (Desktop Edition)
  • Now I can easily search through all (archived) posts
There are a lot of free alternatives (SharpReader, RSSBandit, ...) for reading blogs/feeds, but they all currently fall short for my needs. For the moment I don't regret paying 20$ a year for my Newsgator subscription.

Tuesday, September 6

Custom Visualizers in VS 2005

Visualizers are a new component of the Visual Studio 2005 debugger user interface. A visualizer creates a dialog box or other interface to display a variable or object in a meaningful way that is appropriate to its data type.

Out of the box there are four standard visualizers :
  • Text Visualizer
  • HTML Visualizer
  • XML Visualizer
  • Dataset Visualizer
The first tree work on string objects while the Dataset Visualizer which works for DataSet, DataView, and DataTable objects.

Visualizers are represented in the debugger by a magnifying glass icon. When you see the magnifying glass icon, you can click on it to select a visualizer appropriate to the data type of the corresponding object.

I included a preview of the HTML Visualizer ...

At TechEd 2005 in Amsterdam, I attended the session What's new in the Visual C# 2005 IDE, given by Juval Lowy. I remembered that he showed us a custom sound visualizer and I was pretty impressed how easy it was to create one on your own for a custom class. So I tried it out tonight ...

I created a class Player with some properties (FirstName, LastName, Image, ...) and for that class I wanted to create a custom Visualizer : PlayerVisualizer (see example below). The custom form (visualizer) displays an image of the player and some other player-information.

While debugging I'm now able to see a custom view of the Player object. No more playing around in the command/immediate window to query for the info you're looking for. Just clicking the magnifying glass to call the custom visualizer. Cool, isn't it?

All I had to do was :
  1. Adding a Debugger Visualizer Template to my project

  2. Creating a custom form to display the info I wanted and how I wanted it.
  3. Adapting the template (Show-method)
    • casting to a Player object
    • passing Player object to custom form
    • show custom form
  4. Adding the DebuggerVisualizerAttribute to tell the debugger about the classes that make up the visualizer
More info on how to do this exactly (code) can be found in this excellent article (Creating a Debugger Visualizer) on the MSDN-website.

Saturday, September 3

New Notebook

I have finally switched to my new computer (Dell Latitude D610 - 1.86 GHz - 2 GB RAM - 60 GB Harddisk). It took me some time to install everything I wanted and to move all my data from my old computer.

Installation Details :
  • Partition 1 [Windows XP Professional]
    • Visual Studio .NET 2003
    • Visual Studio .NET 2005 (beta 2)
    • Visual SourceSafe 2005 (beta 2)
    • SQL Server 2005 (CTP June 2005)
    • Microsoft Virtual PC
    • MSDN Library (April 2005)
    • Microsoft Office 2003
  • Partition 2 [Windows Vista (beta 1)]