October 2006 Entries

Working MasterPage Samples

A few people have asked me for a working web site with some of the code from my MasterPage: Tips, Tricks, and Traps article. This download is a web site based on the ASP.NET Personal Web Site Starter Kit and provides a number of the samples from the article. Samples include a master page base class, and an HttpModule to assign the MasterPageFile property for .aspx web forms at runtime. There is an example of content page to master page interaction through a strongly typed Master property, and an example of master page to content page interaction via an event....

What's Wrong With This Code? (#8)

Joe Developer is working with a simple struct: struct Point {     public int x;     public int y; } Joe's tech lead asked him to write a method that will return an array of 10,000 initialized points. Joe wrote following code. Point[] CreatePoints() {     Point[] points = new Point[10000];     for (int i = 0; i < points.Length; i++)     {         points[i] = new Point();     }     return points; } The code doesn't create any runtime errors, but Joe is worried because his tech lead looked at the code and frowned. What could provoke such a reaction? Hint: Joe's lead is a performance nut.

What's In a Workflow Queue Name?

There is a queuing infrastructure in Windows Workflow that facilitates communications between workflows and the outside world. Event related activities, like the HandleExternalEvent and Delay activities, provide a formalized layer of abstraction over this queuing infrastructure. You might never need to know that a queuing service exists if you can get 100% of the job done with components from the base activity library. If you need more flexible messaging, or like Harry, want to work with a low level API, you can use the queuing service to create queues and en-queue messages for your own purposes. Before jumping in, it's worthwhile to study how the built-in activities make...

The Fall Tour

I spent the summer as a hermit. Here are some events where I'll be presenting over the next three months. VSLive! Boston (Oct 24 - Oct 27). On Wednesday afternoon, I'll show you how to bend master pages to do your bidding. There is some great ASP.NET 2.0 content in this show with the likes of Fritz Onion, Miguel Castro, Chris Kinsman, and more. VSLive! Dallas (Nov 14 - Nov 17). One presentation on master pages, and one presentation to help make sense of web site projects, web application projects, and web deployment projects. Central Penn Code Camp (Dec 2). I'll probably do one talk...

Static Doesn't Mean Thread Safe

One misunderstanding I often see is "if I make this member static it will be thread safe". I think this misconception arises because of the boilerplate MSDN documentation that will often say: "Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe." When a .NET framework class appears with the above documentation, it means a developer took the necessary precautions to make the static member thread safe. Perhaps they added a lock, or used some other synchronization mechanism to ensure thread safety. See: Statics and Thread Safety Part...

What Can aspnet_compiler.exe Do For Me?

People often ask what the aspnet_compiler tool can do. The usual answer is "pre-compile an ASP.NET 2.0 web site". The follow up question is: "What good does that do me?". MSDN says the advantages to compilation in general are: Performance Security Interoperability Stability Let's take these one at a time. Performance I say the performance benefits to pre-compiling a site are negligible. Pre-compilation does save some work, but ASP.NET applications in general are slow starters. Think about all the work that happens when the first request arrives. A process has to start. An AppDomain has to load. The cache is empty. The database connection pool...

SiteMap Macro v2.0

Last year I wrote a little macro to generate a web.sitemap file for ASP.NET 2.0. A few people have been asking about support for Web Application Projects, so I've updated the macro. Download. This macro walks through the directories of a web project and adds all the content pages to a ASP.NET 2.0 site map file. If you use URL re-writing or virtual path providers, it won't be able to see those URLs. Chances are you'll need to hand tweak the file afterwards as the macro isn't intelligent enough to devise a good title for each page, but it can...

Don't Try This At Home

I wasn't paying attention when I typed: mstsc /v:name.domain.net /console Unfortunately, I was already sitting in front of the very machine I was trying to reach with terminal services. I took over the console, all right - the screen blacked out. I couldn't get Ctrl-Alt-Delete to provoke a response. If it wasn't for the lights on the case I'd have thought the computer died. It takes 30 seconds or so for the un-credentialed new connection to timeout and return control to the real console. It's a very long, worrying 30 seconds, though. I just wanted to share my anxiety.

MasterPage Issue With ViewState Disabled in web.config

Vivek points out some surprising behavior with master pages. Let's say we want to disable ViewState for all pages by default. All we need is an entry in web.config: <system.web>   <pages enableViewState="false"  /></system.web>       When the ASP.NET runtime generates code for a web form, it will disable ViewState using generated code. The code in the Temporary ASP.NET Files directory for an .aspx will contain a snippet like the following: private void @__BuildControlTree(some_aspx @__ctrl) {    #line 1 "some.aspx"  @__ctrl.EnableViewState = false;  // ...} At some point, we may run into a page that requires ViewState. Arguably, we could say that something on the page should be re-written to use...

Web Client Software Factory - Drop 04

The Web Client Software Factory dropped a new build yesterday. This is the first build I've downloaded. I spent about 30 minutes perusing the documentation and reference implementation, and I am shocked!. My expectations were to open this package and find yet-another-data-access-layer-approach. Ho hum. Instead, this factory positions itself to address leading issues in today's web development practices. Some highlights: The reference implementation uses a model-view-presenter with controller (MVPC) pattern to maximize the testability of code, and centralize control flow and business logic. The docs explain how to implement MVPC using the canonical definition of test-driven development. Write your tests...

What's Wrong With This Code? (#7)

This time, Joe Developer is building a web application for the company intranet. Most of the site is available to anonymous users, but one directory - the adminPages directory, should only be accessible to users in the machine's local administrators group. Joe added the following to the bottom of his web.config, and is feeling pretty secure. <configuration>  <location path="adminPages">    <system.web>      <authorization>        <allow roles="BUILTIN\Administrators" />        <deny users="?" />      </authorization>    </system.web>  </location>  </configuration> Should Joe be worried?

Celebrities in MSDN Documentation

I imagine the MS legal department frowns on the appearance of recognizable names in documentation. Nevertheless, there are a few out there. For instance, the documentation for IXmlSerializable.WriteXml contains a celebrity from Bedrock: // Create a person object.Person fred = new Person("Fred Flintstone"); Over in the Visual FoxPro world, we find a local Microsoft celebrity: IF UPPER(userID) = 'BILLG' && only one user may add tables   RETURN .T.ENDIF   RETURN .F.ENDIF Finally, perhaps someone had a particular GeorgeW in mind when describing sp_denylogin to aspiring DBAs: EXEC sp_denylogin 'Corporate\GeorgeW' If only it were that easy… So, know of any others?

Workflow Policy, Rules, and Collections

Q: Great article on the WWF Rules engine. I am curious how one would implement a rule that is applied to a collection of items, something akin to "IF request.Payments[n].Amount > 10000 THEN request.Payments[n].RequiresApproval = true" A: There are quite a few approaches to choose from. As usual - it depends on the application! One solution is to use a WhileActivity and loop through the collection. This explicit approach would run a PolicyActivity for each item in the collection. The Windows SDK contains an interesting alternative approach in the "Processing Collections in Rules" entry. This is approach is worthy of note...