November 2005 Entries

Sitemap Macro

I wrote a Visual Studio macro to walk an ASP.NET 2.0 project and create a web.sitemap based on the physical layout of files. Download. The macro requires a reference to System.Xml.dll. The macro won’t overwrite or synchronize an existing web.sitemap file, it’s only meant to save some typing if you have an existing project and want to add a sitemap. Once the macro creates the sitemap, you can go in and modify the titles, descriptions, and layout. Update: Fixed the macro to work with IIS based projects, and added Dan Kahler's suggestion to prompt user to overwrite existing file.

Building A New Mouse Trap V: Workflow

When I first heard about Windows Workflow Foundation, I wasn’t particularly excited. “Workflow” has long been a buzzword used by vendors, product managers, and venture capitalists in mind numbing phrases like: “Our workflow solution will leverage your strategic business assets and put you in the fast lane of the information superhighway”. Yawn. Nevertheless, I knew some people who were taking Workflow seriously, so I decided to give the preview bits  a try. Workflow is a success. The designer works well – both the user interface and the programming interface are intuitive. For a good description of the feature set, which...

Membership and Roles

I like to write about a topic before I give a presentation. Writing is my way of organizing random thoughts into an arbitrary collection of opinions. When I signed up to do a presentation at the last local code camp, I got behind on writing about membership and role providers in ASP.NET 2.0. I finally finished the writing this weekend (Part I, Part II). Miguel Castro also covered membership features at the last code camp. Miguel concentrated on the login controls and UI customization while I stuck more to the configuration and other details. Miguel knows a great deal about...

Spot the Authorization Bug

The following is an excerpt from PAG’s “How To: Use Role Manager in ASP.NET 2.0”. You can control access to pages or folders to members of one of the built-in Windows groups by specifying the role in the format BUILTIN\groupName. The following example allows users in the built-in administrators group to view pages in the folder named memberPages and denies access to anyone else.                                                                                      The problem is, the default authorization rule is:     The ASP.NET module responsible for authorization checks iterates through rules starting with the local web.config file, and ending with the “allow all...

Building a New Mouse Trap IV: XML

I had a star schema and an XML document of creamy data to stuff inside. What’s the best approach to updating the dimension tables with new values? There are many tried and true approaches to evaluate. Let’s take the specific case of the Referers table. This table stores a RefererID, and a Referer string. I have an XML document full of Request elements, each with a Referer attribute. I needed to look at each element and find any Referer values that do not exist in the database to insert only new values. <Request Date="2005-11-15T07:59:59Z"         Uri="/Articles/rss.aspx"         Referer=""        ...

Building a New Mouse Trap III: SSIS

Once the web log files were downloaded and unzipped, I transformed them into an XML document and looked for a way to get the records into SQL Server. My first thought was to learn more about SQL Server Integration Services, the successor to DTS. I’ve used DTS in the past to fast-load millions of records into data marts. Although the performance numbers were excellent, I’ve always held misgivings about DTS because the packages were opaque, and difficult to maintain and use in generic solutions. Although I made a fair amount of progress with SSIS, I ultimately ditched the approach...

Building a New Mouse Trap II : Unzip

In 1.1 we needed third party libraries to compress and uncompress data. In .NET 2.0 we have GZipStream and DeflateStream classes. However, as Stephen Toub points out in .NET matters, these classes are don’t handle the headers, footers, and other metadata of popular archive formats like gzip and zip. In looking for the simplest possible solution to unzipping a single file in a windows forms application, I decided to interop with Shell32.dll. The disadvantage appears to be the inability to perform a “silent” operation – the shell always displays a modeless progress dialog no matter what flags are passed to the...

Building New Mouse Traps Part I: FTP

I’m using the holiday break to build yet-another IIS log file retrieval / parser / reporting tool with Visual Studio 2005. Sure, there are plenty of these around already, but not that use Windows Workflow and SQL Server 2005 XML data types. If nothing else, the project was an exercise in learning new areas in 2005 and 2.0. The first task was to retrieve a list of available log files from an FTP server. The 2.0 framework provides FTP support with the WebClient and FtpWebRequest classes. The WebClient is useful if you want a quick DownloadData call to retrieve an...

Design Patterns: A Love Story

Richard tilted his head to watch the waves push flotsam against the boat hull below. Up and down, the flotsam moved. Up and down. Richard had an idea. “Virginia, my dear”, he said to the blond woman beside him. “We’ve been singletons on this ship for a long time”. “I know, Richard”, she replied. “My mean step-mother, the intercepting filter that she is, denies me time with others.” Richard paused for a moment, to contemplate strategy. Her father, with his pipes and filters, would return soon, and force them to communicate over his message bus. He glanced aft, and saw...

Defining a Contract Is Hard

We often talk about interfaces defining contracts. interface UserValidator {     bool ValidateUser(string username, string password); } The above interface seems simple. We can go to any object implementing the interface and invoke the ValidateUser method. Pass in a username and password, and the object will tell us if the user is valid. Still, there is plenty left unspoken. Take the abstract base class MembershipProvider in ASP.NET. MembershipProvider includes an abstract ValidateUser method, just like the one in the interface defined above. Here are the remarks for the method: Takes, as input, a user name and a password and verifies that the values match those...

Debug and Release Builds in ASP.NET 2.0

One of the adjustments to make when moving from ASP.NET 1.1 to 2.0 is how to produce debug and release builds. 1.1 In 1.1 we had the Build -> Configuration Manager menu option. This command launched a dialog box to let you choose from the available build configurations. Visual Studio provided Debug and Release configurations by default. The configuration selected in the Configuration Manager would tell Visual Studio how to compile the code-behind files. A successful compilation would produce a single assembly (.dll) in the bin directory, with a debugging symbol file (.pdb) appearing if the configuration asked for debugging symbols Sometime later, the...

Writing Configuration Files

2.0 provides ability to modify configuration files. As you might expect, it is difficult to modify a configuration file in a locked down environment. As an example, the following code tries to change the compilation section to disable batch compilation and enable debugging. protected void ModifyConfig_Click(object sender, EventArgs e) {     Configuration config;     config = WebConfigurationManager.OpenWebConfiguration("~");       CompilationSection compilation;     compilation = config.GetSection("system.web/compilation")        as CompilationSection;       compilation.Batch = false;     compilation.Debug = true;       config.Save();              } Two problems you’ll quickly run into: The code throws an exception under medium trust because the code needs read privileges on all of the configuration files from which it...

SmartCHART for the Smartphone

A few weeks ago, I took the dive into Smartphones and bought an unlocked MPX-220. Even though the phone isn’t the latest and greatest gadget that some lucky people have, I’m happier with this phone than any phone I’ve ever had. My first late-night project with the 2005 RTM build is a Smartphone 2003 application to scrape traffic information from the state of Maryland’s Coordinated Highways Action Response Team site. Hint: (if anyone is listening) – I could have built the app in half the time if the information was available from a web service or RSS feed. ...

Strong Typing and Nested Master Pages

Here is a little tip for getting a strongly typed Master property when using nested master pages in ASP.NET 2.0. Let’s say you start with the following, top level master page: <%@ Master Language="C#" %>   <script runat="server">       public string BigFooterText     {         get { return BigFooter.Text; }         set { BigFooter.Text = value; }     }   </script>   <html> <head runat="server"/>   <body>     <form id="form1" runat="server">     <div>         <asp:contentplaceholder id="BigContent" runat="server"/>         <asp:Label ID="BigFooter" runat="server"/>     </div>     </form> </body> </html> A second, nested master page provides the content for the top level master. <%@ Master Language="C#" MasterPageFile="~/BigMaster.master"  %> <%@ MasterType VirtualPath="~/BigMaster.master" %>   <script runat="server">       public string LittleFooterText     {         get { return LittleFooter.Text; }         set...

A Look At The Stars

The news in science this week is that NASA researchers think they are looking at infrared glows from the first stars of the universe. I wonder … just how far back we will be able to go? Dr. Mandleblot sat in front of the hooded display as a cat owner sits in front of his cat. He watched the device intently, while the device summarily ignored him. “Only 10 more seconds, Scott, and I will be looking at the very beginning of the universe”, the doctor said, unassumingly. My pulse spiked at the thought. I couldn’t believe how calm Dr. Mandleblot...

Health Monitoring in ASP.NET 2.0

ASP.NET 2.0 includes a nifty new feature known as Health Monitoring. The name might be a bit misleading, as the feature is really an extensible and general-purpose framework for producing and capturing events during the life of an ASP.NET application. Health monitoring can be useful in a number of scenarios, for instance, health monitoring is useful to administrators who need to monitor an application and be notified when a critical error occurs, or to developers who need to add instrumentation to a mis-behaving application. The runtime includes a number of classes to represent events. There is a class to represent authentication...

Scary Software

In honor of Halloween, I was trying to think of the scariest software I’ve ever met. A long time ago, I worked on an embedded project building one of those blood pressure kiosks like you'll find in a drugstore. The brain of the machine was a little 8 bit CPU. Every so often, I’d volunteer my own arm in the machine and measure my blood pressure as a test. You know when you are getting your blood pressure measured in the doctor’s office …… and the rubber bladder is starting to feel extra snug around your arm ...… and you are wondering...

Scott Allen
Posts - 869
Comments - 4493
Stories - 14