Scott Hanselman

Meme Time: Growing Up Geek

October 4, '08 Comments [22] Posted in Musings
Sponsored By

Hanseldork? Ok, it's meme time. Now, you may be surprised to hear that under my cool exterior, I was a nerd in school. No, no, you say! It's not so! Surely you were the most popular kid, Scott? You weren't beaten brutally each day for having glasses that weighed more than your huge head? Nonsense!

Alas, it's true. It's probably true for you as well, Dear Reader. Or, that's what I like to tell myself. ;)

I've written before about how I got into computers, some of the OS's I've run, that I love gadgets, and how my fifth grade teacher took me from an "at risk youth" to a huge dork. I've even done a podcast with my Dad about what it's like to raise a nerd. Of course, the Nerds will Inherit the Earth, right?

Did you grow up a geek?

Let's see what you looked like as a young burgeoning nerd or nerdette.

I'm tagging Phil Haack, Rob Conery, Leon Bambrick, Greg Hughes, and Brad Wilson.

Of course, if you're not tagged, I want to see pics of you as a kid-nerd regardless. Go dig in that shoebox you know you still have. Call your Mom, look at the photo album, and link to this post or leave a link in the comments.

Let's see some nerdy childhood pictures folks!

Technorati Tags: ,,,

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Web Platform Installer: Trying to make it easier to setup for web development

October 3, '08 Comments [15] Posted in ASP.NET | IIS | Tools
Sponsored By

There's a renewed focus, in my opinion, to make things easier to find around The Big Blue Monster. I'm working with a bunch of folks on a more official version of http://www.smallestdotnet.com and some changes around making the .NET Framework easier to find, as a small example.

Getting a machine up to speed for Web Development is another thing that's kind of a hassle because you need to go get (and know to go get) IIS7, Visual Web Developer 2008 Express Edition, SQL Server 2008 Express Edition and the .NET Framework, yada yada yada.

There's a new site at http://www.microsoft.com/web and a new (beta) of the Microsoft Web Platform Installer (blog announcement). It's basically a super bootstrapper that keeps track of where to get stuff and organizes them as profiles.

Microsoft Web Platform Installer

If I select "Your Choice" I get a complete list from a catalog of things that can be downloaded. I can auto-select options from a dropdown like "PHP Developer" or "Classic ASP Developer." Cool that those options are there as well as ASP.NET Developer. There's a manifest that it downloads to get the latest versions of each of these.

Web Platform Installer Choose Components

On the Web Server tab, it'll pick the right IIS modules you'd need to get a site up, but it also shows as options some of the more interesting (and not well publicized) modules like ARR and BitRate Throttling that have been released since IIS7 came out.

If you're running a Web Development shop, it's certainly a quick way to get everything you'd need installed, including the free version of Visual Studio Web Express.

Check it out, and if you have any trouble or find anything interesting, you can report it directly to the team at the Web Platform Installer Forum. If you like it or hate it, let them now. It'd be interesting to see how extensible it can be and if they choose to extend it other developer products.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side

October 1, '08 Comments [32] Posted in ASP.NET | ASP.NET Dynamic Data | ASP.NET MVC | Web Services
Sponsored By

I wanted to write this post because there seems to be a lot of confusion about how ASP.NET WebForms, MVC and Dynamic Data all fit together. Folks may have WebForms applications and want to start looking at ASP.NET MVC but aren't sure if they need to start from scratch or not. Folks might look at Dynamic Data but mistakenly assume it's just for scaffolding administrative sites.

When you're in Visual Studio and you hit "File | New Project" you're given a number of choices. This is a starting point, but it easy to assume that this point is a fork in the road and you can mix them up.

File New Project Dialog

You can (and should) feel free to have Hybrid applications. You can have single Web applications that have all of these inside them (if it makes you happy):

  • ASP.NET MVC
  • ASP.NET WebForms
  • ASP.NET Web Services (ASMX)
  • WCF Services
  • ASP.NET Dynamic Data
  • ASP.NET AJAX

Here's an extreme example. I'll pick ASP.NET MVC Application to start with, but it doesn't really matter. If you're confused as to what web.config entries are required, just make one of each kind of project and compare the files with your favorite diff tool (mine is Beyond Compare).

Ok, so first I've got a Hello World ASP.NET MVC application:

Visual Studio Solution with just ONE MVC application

I'll add a quick LINQ to SQL database connection to the AdventureWorksLT database so I have something to query.

Next, I'll throw a quick ASMX Web Service into this ASP.NET MVC application that returns some data. I create it via File | New Item and select Web Service. I make a quick LINQ expression and a smaller class SmallProduct (a LINQ projection) that is returned. I also make it ScriptService, so I could call it via AJAX if I liked.

namespace Overkill
{
public class SmallProduct
{
public string Name { set; get; }
public string Color { set; get; }
public decimal Price { set; get; }
}

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Products : System.Web.Services.WebService
{
[WebMethod]
public List<SmallProduct> GetProductsByColor(string color)
{
AdventureWorksDataContext d = new AdventureWorksDataContext();
return (from p in d.Products
where p.Color == color
select new SmallProduct
{
Name = p.Name, Color = p.Color, Price = p.ListPrice
}).ToList<SmallProduct>();
}
}
}

What does this have to do with ASP.NET MVC? Nothing. That's the point. This is an ASP.NET 2.0 style ASMX Web Service with an ASP.NET AJAX ScriptService attribute using a .NET 3.x LINQ Query to return the data, all living in an ASP.NET MVC application.

Why doesn't ASP.NET MVC grab the request? Two reasons. First, there's an option on RouteCollection called RouteExistingFiles. It's set to false by default which causes ASP.NET MVC to automatically skip routing when a file exists on disk.

if (!this.RouteExistingFiles)
{
string appRelativeCurrentExecutionFilePath = httpContext.Request.AppRelativeCurrentExecutionFilePath;
if (((appRelativeCurrentExecutionFilePath != "~/") && (this._vpp != null)) && (this._vpp.FileExists(appRelativeCurrentExecutionFilePath) || this._vpp.DirectoryExists(appRelativeCurrentExecutionFilePath)))
{
return null;
}
}

Because the default Route in Global.asax isn't greedy enough to care even if we were routing all requests:

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);

}

However, in my personal experience, File.Exists is a very expensive operation (very is relativeā€¦it's expensive because it hits the disk at all). A best (and example of attention to detail) practice would be to put in an IgnoreRoute call for those pages, directories, and/or HttpHanders. For example:

routes.IgnoreRoute("{myWebForms}.aspx/{*pathInfo}");
routes.IgnoreRoute("{myWebServices}.asmx/{*pathInfo}");
routes.IgnoreRoute("myCustomHttpHandler.foo/{*pathInfo}");
routes.IgnoreRoute("Contents/{*pathInfo}");

Here I'm ignoring .aspx, .asmx, a custom HttpHandler with a custom extension and the whole of the Contents folder. I might even want to set routes.RouteExistingFiles = true which would turn off the File.Exists check and put ALL the pressure for routing on my routes. I'll need to be more careful and explicit, but that's rarely a bad thing. You could also just structure your site such that all your non-MVC things live in their own folder. It's up to you.

Now, let me add a WebForm and *gasp* drag a GridView into it. Wow, I'm a bad person, I've just used the Designer. I was productive so, but what price my immortal soul? ;)

WebForm with a GridView

Seriously, though, use what makes you happy. This grid is kind of lame, so I'll add some ASP.NET DynamicData. However, while you usually see Dynamic Data from a File | New Application point of view, I'm going to just bring a DynamicDataManager control onto the page. You'll also want to confirm that you have DynamicData controls listed in your web.config:

<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.DynamicData" assembly="System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>

I'll add a few things to my WebForms page:

<div>
<asp:DynamicDataManager ID="DynamicDataManager1" runat="server" />
<asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
AutoGenerateColumns="false" DataKeyNames="ProductID" AllowPaging="true" AllowSorting="true">
<Columns>
<asp:DynamicField DataField="Name" />
<asp:DynamicField DataField="ProductNumber" />
<asp:DynamicField DataField="Color" />
<asp:DynamicField DataField="ListPrice" />
</Columns>
</asp:GridView>
<asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true"
ContextTypeName="Overkill.AdventureWorksDataContext" TableName="Products"/>
</div>

In the Global.asax.cs, I'll add these two lines to let the DynamicData system know that we're working on this DataContext:

MetaModel model = new MetaModel();
model.RegisterContext(typeof(AdventureWorksDataContext), new ContextConfiguration() { ScaffoldAllTables = false });

Then, the most important part, I'll want to bring in the ~\DynamicData folder, since that's where DynamicData finds all of its templates. For this example, I really only need ~\DynamicData\FieldTemplates as I'm only using the smallest bit of Dynamic Data functionality.

To do this easily and quickly, I usually make a throwaway new DynamicData Web Application in another instance of Visual Studio, making sure to give it the same name (and hence, namespace) as the one I'm working on. Then I just drag that project's DynamicData folder over into my original application, and ensure that all the designer files and code-behinds are included in the project (Show All files, then right click each one, Include in Project). The rumor is that there will be a quick way in the future to bring a fresh DynamicData folder into an existing app.

Now, I'll hit my page again and then I get shiny Dynamic Data goodness.

DynamicData

At this point I've got a WebForm, Dynamic Data, and a totally random unused WebService living inside an ASP.NET MVC application. Of course, now this begs the question "Is this an ASP.NET MVC application."

Oh, you wanted MVC used also? ;) I'll add a quick Products method to the HomeController:

public ActionResult Products(string color)
{
AdventureWorksDataContext d = new AdventureWorksDataContext();
var smallProducts = (from p in d.Products
where p.Color == color
select new SmallProduct
{
Name = p.Name,
Color = p.Color,
Price = p.ListPrice
}).ToList<SmallProduct>();
return View("Products", smallProducts);
}

Then a quick view, making sure it's derived from ViewPage<List<SmallProduct>>:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Products.aspx.cs" Inherits="Overkill.Views.Home.Products" %>
<%@ Import Namespace="Overkill" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
<ul>
<% foreach (SmallProduct p in ViewData.Model)
{ %>
<li><%=p.Name %> <%=p.Price.ToString("C")%></li>

<% } %>
</ul>
</p>
</asp:Content>

And that works also, visiting /Home/Products, ensuring there's a route that matches. I'll make this Route overly specific:

routes.MapRoute(
"ProductsWithColor",
"Home/Products/{color}",
new { controller = "Home", action = "Products", color = "Red" }
);

And it renders like this:

MVCList

I hope this helps and it's more clear now that it's just "an ASP.NET application."

You can feel free to mix and match. Not everyone can (or should) rewrite an existing ASP.NET application, so it is nice that everyone can use some new features in the same ASP.NET application as their existing functionality.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

October 6th - Seattle/Redmond/Bellevue Nerd Dinner

September 30, '08 Comments [10] Posted in Musings
Sponsored By

Are you in King County/Seattle/Redmond/Bellevue Washington and surrounding areas? Are you a huge nerd? Perhaps a geek? No? Maybe a dork, dweeb or wonk. Maybe you're in town for an SDR (Software Design Review) or a meeting with Steve Ballmer. Quite possibly you're just a normal person.

Regardless, why not join us for some Mall Food at the Crossroads Bellevue Mall Food Court on Monday, October 6th around 6:30pm?

Here's some links to help you remember and add this to your calendar. There's photos of previous Nerd Dinners up on Flickr thanks to Orcmid.

Feel free to invite your friends, bring your nerdy spouses and children - just tell them the details are at http://www.nerddinner.com.* Spread the word!

Add to your calendar

    I hope to see you there!

    * Which very soon will be more than just redirect to this post! ;)

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    jQuery to ship with ASP.NET MVC and Visual Studio

    September 28, '08 Comments [60] Posted in ASP.NET | ASP.NET MVC | Javascript | Microsoft
    Sponsored By

    I've done a series of four podcasts dedicated to JavaScript over the last month. Why? Because of this rockin' sweet announcement:

    Microsoft is going to make jQuery part of the official dev platform. JQuery will come with Visual Studio in the long term, and in the short term it'll ship with ASP.NET MVC. We'll also ship a version includes Intellisense in Visual Studio.

    The Announcement Blog Posts

    This is cool because we're using jQuery just as it is. It's Open Source, and we'll use it and ship it via its MIT license, unchanged. If there's changes we want, we'll submit a patch just like anyone else. JQuery will also have full support from PSS (Product Support Services) like any other Microsoft product, starting later this year. Folks have said Microsoft would never include Open Source in the platform, I'm hoping this move is representative of a bright future.

    jQuery Intellisense

    Visual Studio 2008 has very nice JavaScript intellisense support that can be made richer by the inclusion of comments for methods in 3rd party libraries. Today you can search the web and find intellisense-enabled jQuery files hacked together by the community, but we intend to offer official support for intellisense in jQuery soon.

     image

    JQuery is really complimentary to MS-Ajax. For example, we had been talking about writing CSS-Selector support, but figured, jQuery does it really well, why not just use it?

    JavaScript Libraries Play Well With Others

    I wanted to put together a little demo application that used jQuery to spice up a talk I've given on ADO.NET Data Services. The app would retrieve some data from a Bikes database, and would have some radio buttons to change the color queried.

    The whole application is a single static page. There's no code-behind and the only server-side work is the data retrieval from SQL. However, the concepts could be applied to ASP.NET WebForms or ASP.NE T MVC.

    Here's a one page app using:

    • ADO.NET Data Services and it's JavaScript Client Library
    • ASP.NET AJAX
    • ASP.NET AJAX Client Templating (Preview)
    • jQuery 1.2.6

    It looks like this:

    image

    Here's what's going on underneath. First, I'm retrieving data from SQL Server and I need it in JSON format. I'm  using the AJAX Client Library for ADO.NET Data Services to make a REST (GET) query to the back-end. To start with I'll just get the data...I include "datatable.js" as a client-side script and use Sys.Data.DataService() to make an async query. In JavaScript you can tell it's a Microsoft type if it's got "Sys." front of it.  All the client support for ADO.NET Data Services is in datatable.js.

    I'll be getting back dynamically created JSON objects that look just like my server-side data. In the query I'm asking for the top 5 results given a color.

    BTW, the first line of LoadBikes() is a little JavaScript syntax that says "if q isn't there, then make a q that equals "Red."

    <script type="text/javascript" src="Scripts/DataService.js"></script>    
    <script type="text/javascript">
    var bikes;

    Sys.Application.add_init(function() {
    LoadBikes();
    });

    function LoadBikes(q) {
    q = q || "Red";
    var svc = new Sys.Data.DataService("bikes.svc");
    svc.query("/Products?$filter=Color eq '" + q + " '&$top=5", OnProductsLoaded);
    }
    ...

    When I get back the results from the asynchronous query call, I could use string concatenation with the ASP.NET AJAX Sys.StringBuilder type to build HTML on the fly like this:

    var html = new Sys.StringBuilder("<ul>");
    for (var i = 0; i < result.length; i++){
    html.append("<li><div class=\"bikerow\">");
    html.append("<img src=\"bikes.svc/Products(" + result[i].ProductID + ")/Photo/$value\">" + result[i].Name + " " + result[i].ListPrice);
    html.append("</div></li>");
    }
    html.append("</ul>");
    $get("tbl").innerHTML = html.toString();

    There's MANY ways to get the exact same results in JavaScript when you introduce different libraries. There's tradeoff's between size, speed, maintainability, and your happiness. It's nice to pick and choose.

    Rather than using StringBuilder, I'll use the new (preview) ASP.NET AJAX 4.0 Client Template stuff from BLR, Dave Reed, Boris Rivers-Moore and Nghi Nguyen. This is more declarative and easy to maintain way to accomplish the same thing.

    <div id="bikes" class="sys-template">
    <ul>
    <li>
    <div class="bikerow">
    <img sys:src="{{'bikes.svc/Products(' + ProductID + ')/Photo/$value'}}"/>
    {{Name + ' ' + ListPrice}}
    </div>
    </li>
    </ul>
    </div>

    This is a declaration of what I want the table to look like with {{ binding expressions }} in curly braces. The img src= is an ADO.NET Data Services HREF to a product image in the database like "/bikes.svc/Products(740)/Photo/$value" that returns an image directly.

    I'll add ASP.NET AJAX's JavaScript library along with the Preview Templates script from CodePlex:

    <script type="text/javascript" src="Scripts/MicrosoftAjax.debug.js"></script>
    <script type="text/javascript" src="Scripts/MicrosoftAjaxTemplates.debug.js"></script>

    Then, when things are initialized, I'll $get() that template and make a Sys.UI.DataView and store it in a variable called "bikes" and when asynchronous call returns, I'll take the array of data from result and apply it to the DataView.

    <script type="text/javascript">
    var bikes;
    Sys.Application.add_init(function() {
    bikes = $create(Sys.UI.DataView, {}, {}, {}, $get("bikes"));
    LoadBikes();
    });
    ...
    function OnUsersLoaded(result){
    bikes.set_data(result); ...

    Now, I'll start leaning heavily on the jQuery library to change the background colors of just the even-numbered items in my list. I'll also add 100ms animation that draws a border and increases the font size of the item the mouse is over. Notice the "chaining" of the functions as I modify the div. Each method returns the jQuery object so you can increase fluency with chaining as much as you like. I'll also use jQuery to easily setup a group of click events on the radio buttons.

    The complete hacked-together code is this:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Friggin' Sweet</title>
    <link href="styles.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="Scripts/MicrosoftAjax.debug.js"></script>
    <script type="text/javascript" src="Scripts/MicrosoftAjaxTemplates.debug.js"></script>
    <script type="text/javascript" src="Scripts/DataService.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.2.6-intellisense.js"></script>
    <script type="text/javascript" src="Scripts/DataService.js"></script>
    <script type="text/javascript">
    var bikes;
    Sys.Application.add_init(function() {
    bikes = $create(Sys.UI.DataView, {}, {}, {}, $get("bikes"));
    $(".colorfilter").click(function(e) {
    LoadBikes($(this).val());
    });
    LoadBikes();
    });

    function LoadBikes(q) {
    q = q || "Red";
    var svc = new Sys.Data.DataService("bikes.svc");
    svc.query("/Products?$filter=Color eq '" + q + " '&$top=5", OnProductsLoaded);
    }

    function OnProductsLoaded(result) {
    bikes.set_data(result);

    $("ul li:even").css("background-color", "lightyellow");
    $("ul li").css("width", "450px").css("font-size", "12px");

    $("div.bikerow").mouseover(function(e) {
    $(this).animate({
    fontSize: "18px",
    border: "2px solid black"
    }, 100);
    }).mouseout(function(e) {
    $(this).animate({
    fontSize: "12px",
    border: "0px"
    }, 100);
    });

    }
    Sys.Application.initialize();
    </script>
    </head>
    <body xmlns:sys="javascript:Sys">
    <form id="form1" runat="server">
    <input type="radio" class="colorfilter" name="color" value="Red" />Red
    <input type="radio" class="colorfilter" name="color" value="Silver" />Silver
    <input type="radio" class="colorfilter" name="color" value="White" />White
    <input type="radio" class="colorfilter" name="color" value="Multi" />Multi
    <input type="radio" class="colorfilter" name="color" value="Black" />Black
    <div>
    <div id="tbl">
    </div>
    <div id="bikes" class="sys-template">
    <ul>
    <li>
    <div class="bikerow">
    <img sys:src="{{'bikes.svc/Products(' + ProductID + ')/Photo/$value'}}" />
    {{Name + ' ' + ListPrice}}
    </div>
    </li>
    </ul>
    </div>
    </div>
    </form>
    </body>
    </html>

    And it looks like this. Notice that I've got FireBug open and you can see three AJAX calls via ADO.NET Data Services with different queries. I'm hovering the mouse over the second bike, so its font is larger it has a border.

     image

    All of the scripts getting along happily. My code clearly sloppy, but this is a good example of how jQuery provides functionality that the Microsoft libraries don't. Things are better when the libraries are used together. JQuery complements ASP.NET, ASP.NET AJAX and ASP.NET MVC nicely and jQuery already has a large following within the .NET community. That's why we're going to ship, support and promote jQuery in ASP.NET, ASP.NET MVC and Visual Studio going forward.

    This was a simplistic example and I'm sure you've got better ideas, so I'd encourage you to go around the Net and get involved in the dynamic jQuery community. If you've used jQuery on an ASP.NET site, sound off in the comments.

    JQuery Resources

    Hanselminutes JavaScript Podcast Series

    * Thanks to Pablo Castro for his Bike database and ongoing help. Big thanks to Scott Koon for helping me debug my demo at 2am this morning using CrossLoop while kindly not asking what I was working on. Also thanks indirectly to Rick Strahl for his excellent .NET (and often jQuery) blog.

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.