Web Development

Tips, tricks, experiences, and fun with ASP.NET, jQuery, and other web-related tech.

Switch Default Browser in Visual Studio without "Browse With..."

Visual Studio has a nasty habit of forgetting your default browser settings at seemingly arbitrary times. Couple that with the fact that you can only really switch your default browser in VS using this "Browse With..." context menu on a browsable ASPX or HTML page (and the fact that in your MVC solutions you probably don't have a directly browsable ASPX or HTML page) and this whole thing is a nightmare. Enter Hanselman, who has posted a Powershell solution to the problem. YAY!

Book Review: Testing ASP.NET Web Applications

I got a copy of Testing ASP.NET Web Applications a while ago but it's taken me some time to get through it because I wanted to dedicate the time and attention to it that it needed. There really aren't many decent books that discuss testing all different aspects of web applications (though there are several dedicated specifically to security testing). The content in this book is something I've been trying to find for a long time in a format aggregated all together in one place and, despite a few rough edges, I'll be recommending it to my QA friends this...

How to Consume MSDeploy Staged Web Site Output in a Wix Installer

MSDeploy is a pretty cool installer technology, but it's not what everyone uses, and my personal experience so far is it's not flexible enough for me. I'm not the biggest fan of Windows Installer, either, but you can't say it isn't flexible. As part of a recent project, I was working on a web site installer. I wanted Wix to take my web site - including the transformed web.config files and such - and package it into an installer. I'm no Wix expert, but this didn't appear to be as straightforward as you might think. The usual way...

Unit Testing an ASP.NET VirtualPathProvider

The VirtualPathProvider class is (in my opinion) a fairly underused mechanism for extending where different files in your application come from. You can create providers that get files from zip archives, databases, or anywhere else you need. The problem is, unit testing them is a nightmare. You either have to run the tests from inside a real web app or you have to set up so many mocks that your tests become fragile or unmanageable. Ugh. Turns out there's a third option - create a special AppDomain that has just enough real setup to support working with the...

Developing as a Non-Admin: Testing WCF Services

If you're developing as a non-admin user and writing WCF services (or supporting entities like behaviors, etc.), you probably not only are unit testing the code but also want to write an integration test or two that actually fires up a real WCF service, makes a couple of requests, and validates the responses. You may also have seen this exception: System.ServiceModel.AddressAccessDeniedException : HTTP could not register URL http://+:1234/ServiceUnderTest/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). Following that link, you'll see that the reason you can't start your service listening to...

The Importance of TypeId in ASP.NET MVC DataAnnotations Validation Attributes

Messing around with ASP.NET MVC 2.0 (in VS2010 RC1), specifically the validation done with DataAnnotations, and created a simple no-op custom validator attribute like this: [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class MyCustomAttribute : ValidationAttribute { public MyCustomAttribute() : base("Custom Error Message: {0}") { } public override bool IsValid(object value) { return true; } } Similar to the way the sample "PropertiesMustMatchAttribute" is set up - enabled on a class so you attach it to the model, not a property on the model, and set so you can...

Separating Metadata Classes from Model Classes in DataAnnotations Using Custom TypeDescriptionProviders

I haven't done much work with ASP.NET Dynamic Data but in a recent project I started working with it and instantly ran into a dilemma. First, let me explain the project setup. I have a database project that outlines the schema of the database, the stored procedures, all of that. I have a database client project that has some services and a LINQ to SQL data context that I can distribute to clients who want to go that way. I then have a Dynamic Data project for managing the data and a separate web application that will consume the...

Performance Profiler Showdown for .NET

I recently had to do some performance profiler evaluation for .NET applications and I figured I'd share my results. Note that it's as scientific as I could make a subjective review (e.g., "friendly UI" might mean something different to you than to me), but maybe it'll help you out. Also, I'm not a "profiler expert" and, while I've used profilers before and understand generally what I'm looking at, this isn't my primary job function. The five profilers I tried out: Visual Studio 2008 Team System Developer Edition (there's a profiler that comes along with the...

Convert a Relative Path to Absolute Path with jQuery and ASP.NET AJAX

I was messing around with relative paths to files (e.g., "../images/error.gif") and needed to convert them to absolute paths (e.g., "http://server/images/error.gif") on the client but couldn't figure out how. Then I saw this nifty trick to HTML encode things using jQuery and it gave me an idea. String.toAbsolutePath = function(relativePath) { /// <summary> /// Converts a relative file path into an absolute file path. /// </summary> /// <param name="relativePath" type="String"> /// The string with the relative path, like "../foo/bar.gif" /// </param> /// <returns type="String" /> var path = $("<div style=\"background-image:url('" +...

Parsing Currency Values with ASP.NET AJAX

I had to parse a culture-sensitive currency value from a string and couldn't figure out how to do it. I'm using ASP.NET AJAX to do String.localeFormat("{0:c}", value) for writing a currency value to a textbox, but getting it back out... not so easy. The Number.parseLocale extension provided with ASP.NET AJAX is cool for parsing out numbers in a culture-sensitive fashion... if they don't have a currency symbol. So, time to hook that up. Here's what I came out with: Number.parseCurrency = function Number$parseCurrency(str) { /// <summary> /// Parses a string containing a culture-sensitive currency value into a number. ///...

Replace jQuery Validation Message Formatting with ASP.NET AJAX String.format()

I'm working on a site where we're using both ASP.NET AJAX and jQuery to get things done. This includes jQuery Validation for client-side validation functionality. One of the things that comes with jQuery Validation is a $.validator.format method that replaces the {n} style parameters in a string with arguments - basically, a very lightweight String.format. ASP.NET AJAX provides a really nice implementation of String.format that is pretty full-featured and understands format strings. For example, you can do String.format("{0:d}", mydate) to format a date in short date format. Snazzy stuff. Unfortunately, the jQuery Validation one isn't that robust... so I figured I'd marry...

Book Review: Professional ASP.NET MVC 1.0

Professional ASP.NET MVC 1.0 is definitely one of those books you should have on your shelf if you work with ASP.NET MVC or are considering the move. It covers a good range of topics at a nice level of detail, which is surprising considering it's not one of those four-inch-wide mammoths you're probably familiar with. The topics covered are: NerdDinner - A walkthrough of making a fully-functioning MVC app from start to finish Model-View-Controller and ASP.NET ASP.NET > ASP.NET MVC Routes and...

Free Typemock Isolator Licenses - ASP.NET Bundle Launch

Typemock has released a new package for unit testing ASP.NET which includes their Isolator mocking product and an add-on called "Ivonna" that lets you mock a full ASP.NET request lifecycle without running the page through a web server. As part of the launch, they're giving away free licenses. Check out how to get yours now!

Review: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008

I just got finished reading through ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008 by Vince Varallo, and I came out fairly underwhelmed. I read through this book thinking, with a title like that, it would take me through creating an enterprise-class application, complete with all of the things one would think are a part of such an app. As it turns out, I think the title should be something more like "Introduction to N-Tier Development in ASP.NET." Each chapter is set up in the same format, and it's a decent format - outline the problem, explain the design, implement...

Challenges of Multi-Tenant, Enterprise ASP.NET Applications

I've been doing ASP.NET for a while, mostly at my current employer where we make large-scale online banking web sites. During that, what I've noticed more and more as new features come out for ASP.NET is that there's a heavy focus on rapid application development - drag, drop, and ship - and less around the idea of creating a commercial application using ASP.NET. There are a few products like Community Server and DotNetNuke out there, but not many (or not as many as there could be) and I'd wager a lot of it has to do with lack of framework...