December 2005 Entries

A Message For You

Just figure out what the following program writes to the console... using System;using System.Collections.Generic;using _ = System.Text.StringBuilder;using __ = System.Console;using ___ = System.Collections.Generic.IEnumerable<int?>;class wtf{    static void Main()     {        _ _ = new _().Append(_2());        int i= 0; foreach(int? x in _1())        {            _[(int)((x ?? i) < 0 ? i ^ 2 % 10 : x)] = _2()[i++];        }         __.WriteLine(_.ToString());    }    static char[] _2()    {        return        (              "H"      +      "Y"                    +            "E"     +     "N"                    +             "A"    +    " "                    +              "P"   +   "A"                    +               "W"  +  " "                    +                "P" + "R"                    +                 "E"+"Y"                         ).ToCharArray();                    }        static ___ _1()    {        int?[] _ = {                       0, 10, 11, 6,  1, 5, 3,                     /*~~~~~~~~~~~~~~~~~~~*/                     12,  8,  9, 2, 13, 7, 4                    };        foreach (int? x in _)             yield                    return       null              ??              x;    }} Who is gonna port this to VB?

Profile Addendum

There are a couple articles on the web saying you can use a base Profile class like so: using System;using System.Web.Profile;public class CustomProfile : ProfileBase{        public string PetName     {        get { return _petName; }        set { _petName = value; }    }    private string _petName;      } Then use the inherits attribute in web.config like so: <profile inherits="CustomProfile"/> I hope I can save you some time by pointing out the above setup doesn’t work. You’ll find the HttpContext contains a non-null Profile object, but SQL Profiler will confirm that ASP.NET never populates the object with data from the database. Perhaps the above approached worked in pre-RTM bits, I’m...

Low Profile

New article on OdeToCode: Profiles In ASP.NET 2.0 One good reason to inherit from a custom base class is that we can add additional logic to the Profile object. For instance, we can add validation logic to the Age property to ensure the user provides us with a sensible age, and not a value like 443. Read more…

Rambling about ASP.NET Themes

If I go to the trouble of designing multiple ASP.NET Themes using skin and css files, chances are I will let a user choose the theme they find most pleasing. To let the user choose a theme, I’d first have to know what themes are available…. Plan 1 I could maintain the list of available themes in a configuration file, or in a database table. When I add new themes, I’ll have to update the file or table. A better design would be for the application to figure out which themes are available auto-magically, perhaps by using a class provided by...

Event Order

I was going to write a short blog post about event order when a MasterPage is present, but I found MSDN covers the topic well: “Events in ASP.NET Master and Content Pages”. Notice the MasterPage’s Init event will fire before the content page’s Init event, but the content page’s Load event fires before the MasterPage’s Load event. Sound confusing? Well, the MSDN doc offers advice in a declarative form: “The sequence of events in master and content pages rarely is important for you as page developer”. If you find the order of events is important, you might be tightly coupling your...

Return of the Web Project

Do you remember the mood at the end of “The Empire Strikes Back”? Darth Vader froze Han Solo in carbonite, then proceeded to slap Luke around like a hockey puck. Just when we thought all was lost, along came “Return of the Jedi”. Luke broke out some new kung-fu moves, and Princess Leia donned a bikini (which perhaps not surprisingly, spawned this website). The galactic mood was on a definite upswing. Similarly, the “project-less” web project in Visual Studio 2005 left little hope for some ASP.NET applications to make an easy transition to 2.0. Fortunately, ScottGu announced a preview of the...

Death by Unhandled Exception

In .NET 1.1, an unhandled exception would terminate a process only if the exception occurred on the main application thread. The runtime would silently swallow unhandled exceptions on other threads to prevent termination. I’ll leave it for the reader to decide if this is behavior is naughty or nice. In .NET 2.0, unhandled exceptions on any thread will most likely terminate the application (see Exceptions In Managed Threads for details). For ASP.NET developers taking threading into their own hands to implement a “fire and forget” strategy, it’s important to realize this change in behavior. Imagine the following code inside a...

CLR Profiler and the WebDev Server

CLR Profiler for the .NET Framework 2.0 is available for download. The profiler is a good tool to use when you want to find out what’s happening in memory. For instance, ASP.NET developers using InProc sessions state are always curious about how much memory they are using. Assuming the web project is file system based, the first step is to get CLR Profiler to work with the development web server: WebDev.WebServer.exe. The profiler can’t attach to a running process, so you have to tell the profiler how to launch the web server. WebDev requires at least two parameters: a port...

Taking Care Of Pre_Init

The Page class exposes a Pre_Init event because the MasterPageFile and Theme properties need to be set early in the lifecycle of a web form. Pre_Init is the event to hook if you want to assign these properties dynamically in code. The natural question is how to implement master page and theme selection for all web forms in an application without adding a Pre_Init event handler to every single web form. Brock Allen has one elegant solution, which is to use an HttpModule. Brock’s module hooks the PreRequestExecuteHandler and ultimately handles all the PreInit events with a single method in...

Unveiling Visual Studio Commands

Visual Studio 2005 customizes it’s menus based on a category you select when running the IDE for the first time (this is true of the Pro edition, I’m not sure about Standard and Express). I typically pick “General Development Settings” to avoid the C#, VB.NET, or Web Developer stereotypes. The problem with using “General Development Settings” is I can’t develop anything specific [rim shot, cymbal crash]. Seriously, one irritation with the setup is that my menus are probably different from your menus. I read about File -> Export Template, but I don’t see any such command on my File menu. I’ve...

Snippets

Code snippets are a great productivity feature in Visual Studio 2005 (or a mind rot – depends on your perspective). Michael Palermo even has a site dedicated to code snippets: GotCodeSnippets.com. Code snippets are easy to author. I became tired of typing in the same keystrokes ...

The Great Migration

I popped into the Central Penn Code Camp this weekend and did a presentation on ASP.NET 2.0. There are plenty of presentations on the new features of ASP.NET - membership and master pages, web parts and wizard controls, the list goes on forever. I took a different approach. The problem is, you don’t get all the new features for free. 1.x programmers need to unlearn a few concepts, and migrate their existing code. The changes catch people off guard because the changes don’t get as much attention as the bells and whistles. Migration makes people angry. I know, because I have...

Conditional Compilation In ASP.NET 2.0

Conditional compilation allows you to select sections of code to include or exclude from compilation depending on the presence of a constant. This feature is available in both C# and VB.NET. The following page needs DEBUG and MYCONSTANT defined to execute both Response.Write methods at runtime. protected void Page_Load(object sender, EventArgs e){    #if DEBUG    Response.Write("DEBUG is defined <br/>");    #endif    #if MYCONSTANT    Response.Write("MYCONSTANT is defined <br />");    #endif} In 1.1 it was easy to define constants for a web project, but there is no project property page with this option in 2.0. The ASP.NET platform controls compilation, so we need to feed ASP.NET the information. First, ASP.NET will define a DEBUG constant...

Scott Allen
Posts - 869
Comments - 4493
Stories - 14