March 2006

MSDN Webcast report: ASP.NET Soup To Nuts - Tips and Tricks

I had a chance to check out the “Tips and Tricks” MSDN Webcast from the ASP.NET Soup to Nuts series - there’s so much stuff in 2.0 that I figured it was well worth my time to get a refresher/review, especially since, like most MSDN webcasts, it happened at noon. Again, like every other MSDN webcast, my lunch wasn’t ready when it started. Wireless laptops are handy. :)

Here are my notes. Has anyone else had any experiences with these features?

The webcast was basically a response to questions that the Bill had been asked over the course of the series so far, so there wasn’t much of a slide deck, just a series of demos covering various bits of .Net, including…

Wizard control

I’ve implemented a few wizard-type multi step processes for data entry in the past, and while it’s a lot easier to do it in ASP.NET than, say, PHP, it still hurts a ton. The new Wizard control appears to take care of a lot of the mess for you, and it’s definitely going to get a workout when I have to do the next one of these.

Multiview control

Simplifying the above, this appears to be a replacement for manually managing Asp:Panel controls and their visibilities depending on what’s going on - I know I do a ton of that already, so if there’s a nicer way to handle these cases, bring it on!

Validation controls

I was already well aware of these (they do save a lot of time), but it struck me as they went through the demo that I always invoke them from code view (ASP.NET code, not the C# code file). I spend most of my time in this view, probably because of too many burns in the 2003 days, but I really should give the graphical editor another try. “Act like it’s a demo” might be a neat mantra to improve my productivity. :)

Binding to XML

This is just another example of DataSource objects, in this case an XmlDataSource. Nothing new here for me, but I need every reminder to use the built in controls that I can get - I tend to do this crap with code still.

urlMappings section of system.web

Where did this come from? Anything that remotely approximates .htaccess/mod Rewrite in the Apache world needs to be sent to me via FedEx - it’s the weakest part of IIS, as far as I’m concerned.

FileUpload control

I ported some of our 1.1 code to this a while back. It’s still not clear to me if the 2.0 version has the same problems with big files (several clients uploading really big files at the same time can cripple a server). Anyone?

Setting focus to fields on startup

Not too exciting, just putting textBox.Focus() into the Load event for the page. I guess Focus is new in 2.0. When they started talking about default controls I thought they were going to talk about dealing with the enter key in forms.

MaintainScrollPositionOnPostback

This could be a handy page directive for big pages. I need to review the directives in 2.0…

New properties for the Label Control

Things like AccessKey, AssociatedControlID, etc really show how the Label control has gone from a “why bother” widget in 1.1 to something that makes accessibility easy. I really got tired of trying to do things the “right” way and the ASP.NET way in 1.1 - they were really at odds back then.

Technorati Tags: , ,

.Net
MSDN

Comments (0)

Permalink

Converting to an ASP.NET web farm, part 1

I recently implemented an ASP.NET web farm (i.e. a set of load balanced servers running the same set of applications. This took forever to finally implement due to other priorities, but system stability was starting to suffer, so we went for it. The total process took about a week (at 70% time or so), as we had to retrofit the existing applications. It should take about a month to write it all up, but there’s a handy-dandy category for it should you want to read along.

The biggest complication involved user-uploaded content - we’ve got a few apps with pictures and audio files sent in by users (either the public or administrators). While some of the applications had been designed to put that stuff in the DB, it turns out that web applications use the database quite a bit, and converting the rest of the sites to store data as BLOBs seemed inefficient. We ended up still using the DB server, but as a simple media share using Windows file sharing instead of taxing poor ol’ MySql.

The first thing that had to change was our firewall. For reference, we needed to open tcp ports 135, 137, 139 and 445 between each server, and we also enabled ICMP traffic.

Next up: file permissions, part one of a thousand.

Load Balancing

Comments (0)

Permalink

Thrust Labs rule #1: use meaningful variable names

I should have committed this lesson to memory years ago after some kind of time wasting mix-up between a test script called “test” and the UNIX test command (which, in hindsight, may have been more of a path issue, but the other lesson was to not work on assignments at 4 am the night before they’re due), but here we go again:

Never ever ever use throwaway variable names.

Case in point: inspired by my earlier thoughts on desktop application development, I decided to try Cocoa programming. I’m just at the poking-around stage right now (I miss MSDN’s level of documentation already, even when it’s wrong), but I lost an hour or two on this gem:

- (void) loadPicture:(NSString *) filename
{

img = [[NSImage alloc] initWithContentsOfFile: filename];
if(img)
{
[pic setImageScaling: NSScaleProportionally];
[pic setImage: img];
[pic setNeedsDisplay:YES];

}
else
{

NSLog(@”img failed”);

}

}

“pic” was an NSImageView control, and there weren’t any errors, but the damned thing wouldn’t ever change its picture. Further debugging showed that messages weren’t going to it at all:

if([pic isEditable]) NSLog(@”YES”);
[pic setEditable: NO];
if([pic isEditable]) NSLog(@”YES”);

That yielded two consecutive YES entries in the log.

In the end, renaming “pic” to something more meaningful solved the problem. I’ve yet to find a Cocoa or Objective-C reserved words list, but I suspect pic is on it. Of course, meaningful names will avoid a good chunk of the need for such a list anyway.

Technorati Tags:

Cocoa
Programming

Comments (2)

Permalink

Web 2.0 or Star Wars?

I was proud of my score on Cerado’s Web 2.0 or Star Wars Quiz until I read the score interpretations at the bottom. Of course, the convergence of Web 2.0, Star Wars, and the concept of having a life might not be the best fit - maybe a Web 2.0 or Hockey Player quiz might be a better bit of outreach for the web community, or it would be, if this was 1989 and people still thought computers were dorky. Whatever, just posting the link felt wasteful. (via Monkey Bites)

Interweb++

Comments (0)

Permalink

Harsh reminders: Ampersands and System()

Filed under “whoops”:

I wanted to look for a resource leak in one of my apps, but didn’t want to bother installing (and learning) some load test utility (which I really need to do, but not this morning). I made a quickie perl script:

NOTE: there should be semicolons after the system calls, but WordPress is returning error 503 if I do that. I’ll have to look into it later (between the “no image uploads from ecto” bug in 2.0.1 and this error in (I’m guessing) 2.0.2, I’m really loving WP right now…)

while($counter++ < 50000)
{
print $counter . “\n”;
system(”curl http://url.com > /dev/null”)
}

Unfortunately, my URL had parameters:

while($counter++ < 50000)
{
print $counter . “\n”;
system(”curl http://url.com&x=5 > /dev/null”)
}

It only took a second after I ran it to realize that I’d just spawned hundreds (growing into thousands) of requests with the ampersand being interpreted as “run in the background,” which was good for load I suppose, but not good for a lot of other things.

Proper code:

while($counter++ < 50000)
{
print $counter . “\n”;
system(”curl http://url.com\\&x=5 > /dev/null”)
}

And yes, my first run only had a single backslash, which was ignored as an invalid escape sequence. Urgh.

Now if I could just recreate the leak…

Technorati Tags: , ,

Perl

Comments (2)

Permalink

The whole web/desktop thing

I finally made some time to watch the Evening at Adler Mac OS X developer panel discussion, and coincidentally it was on the same day that I finished listening to the Carson Workshops Future of Web Apps panel. Panels. Lots of panels. So. Many. Panels.

Anyway, interesting thoughts from both sides, but two struck me:

“Desktop apps are hard to make”

This was, not surprisingly, from the web guys (Carson). I’ve only been a “professional” web developer for a year and a half or so, with 9 years of desktop/hybrid app development to fall back on, so my perspective is a bit skewed. Desktop apps are easy. Fine, good desktop apps are a bit more work, but there are enough widgets out there that a passable 1.0 app shouldn’t be that hard to deal with, at least if you’re someone like me - someone who, as my boss said, has the design sense of a hamster.

“AJAX will replace a class of apps, but desktop apps will thrive”

That’s from the desktop folks (Adler), although it was echoed in some other Carson talks (Flickr’s desktop photo importer comes to mind). Time will tell if that’s the next “640K is enough for everyone” line. In any case, there’s obviously a big market for desktop applications - I only subscribe to one web service (which is in fact debatable, since it’s Yahoo Music Unlimited, which is web-served, but requires a desktop client), but I seem to buy new software at a rate of a program every other month.

So why aren’t desktop apps getting any press in the age of Web 2.0? There are a ton of design blogs out there, and it’s obviously easier to link to a site and let the user experience exactly what you’re talking about, but I feel like I should see more press on desktop stuff.

Of course, this is likely biased by what I read - to get up to speed on web work, I had to skew my reading a lot. Maybe it’s time to go the other way - any recommendations?

I think the main thing that’s on my mind today is why I don’t develop more desktop stuff, even if it’s just for my use. One of the nice things about the web is the near-instant gratification, which is increasing with new stuff like Rails. I started web development as a hobby when I worked on desktop stuff. With my new responsibilities, maybe it’s time to flip that around.

General

Comments (2)

Permalink

Data Binding a Repeater to a SortedList of structures

Kelly’s comment in the phone numbers in data bound controls post reminded me of something I did this morning:

The problem: I had a bunch of data that I needed to report on, based on date. Unfortunately, there were a bunch of different dates in the table that needed to be aggregated (various timestamps for events in a record’s life) that couldn’t be summed up in one SQL statement.

The solution: I love the System.Collections namespace, so I went with a structure containing the counters, and stored one structure per day in a SortedList. There were three counters that needed to be rolled up, so three DataReader.Read() loops later, I had my data structure.

But how to render it?

Once again, I had to use every fibre of my being to avoid implementing an OnDataBound event handler and doing a bunch of FindControl() calls. Yes, that was a good step away from the old ASP style of Response.Write() calls embedded in the table markup, but come on, it’s 2006 already (although this was ASP.NET 1.1)

The rendering code:

_report.DataSource = counters;
_report.DataBind();

So how do we bind a SortedList (or a Hashtable if you don’t care about the order)?

Within the ItemTemplate of my Repeater, I used this for the key (the date):

<%# ((DateTime)((DictionaryEntry)Container.DataItem).Key).ToString(”d”) %>

For the individual elements of the structure:

<%# ((Record)(((DictionaryEntry)Container.DataItem).Value)).aCounter %>

A few too many brackets for my liking, but hey, it beats hiding it in a CodeBehind.

.Net
Data Binding

Comments (0)

Permalink

IE7 is something I would design. That’s not good.

Jonathan Rentzch compares IE7 and Safari:

I’m glad Microsoft is embracing translucency in Vista’s interface. With any luck, I’ll be able to make their atrocious user interface completely invisible.

Technorati Tags: ,

General

Comments (0)

Permalink