.net, c#, asp.net, linq, htpc, woodworking

Jarrett's Tech Blog - For October 2008

  1. LINQ Syntax Choice

    Which LINQ syntax do you prefer?  The fluent style or the query style?

    Fluent and Query LINQ Syntax

    I personally prefer the Fluent style as it appears to come natural to me.  However, I have yet to deal with some of the more complicated joins that may work better with the query style syntax.

    Posted by Jarrett on October 17 at 10:32 PM

  2. ASP.Net MVC Beta Crashing IIS7

    With the new beta release of the MVC framework, I updated BlogSvc to compile and run with the new dlls that are now in the GAC.  After deleting from the gac and finally copying the dlls to my bin folder I things running smoothly from within Visual Studio.  However, when I deploy to IIS7, I am getting a crash.


    I’ve tried cleaning out all the applications in my IIS and also restarted the AppDomains, sites, servers.  I’ve also tried rebooting.  Anyone have any idea’s?  Does the beta run on your IIS7 in Vista?

    I’ve asked this question on StackOverflow: Why is Asp.net MVC Beta crashing my IIS7?

    Update: I toggled data execution preventions (DEP) and a couple a reboots later and the issue cleared up.

    Posted by Jarrett on October 16 at 5:33 PM

  3. Deploy MVC Application

    I previously thought Visual Studio.NET only supported automatically deploying “Web Site” projects but it also works with “Web Application” and “MVC” projects. Right-click on your project and choose publish.


    After choosing publish it will upload all the files based on your “Copy” choice.  You can watch the output window to track the progress:

    ------ Publish started: Project: WebMvc, Configuration: Debug Any CPU ------
    Connecting to ftp://ftp.atomserver.net/wwwroot/...
    Deleting existing files...
    Publishing folder /...
    Publishing folder App_Data...
    Publishing folder App_Data/www...
    Publishing folder App_Data/www/blog...
    Publishing folder App_Data/www/blog/WelcomeToBlogService06...
    Publishing folder App_Data/www/media...
    Publishing folder App_Data/www/pages...
    Publishing folder js...
    Publishing folder themes...
    Publishing folder themes/default...
    Publishing folder themes/default/images...
    Publishing folder bin...
    ========== Build: 5 succeeded or up-to-date, 0 failed, 0 skipped ==========
    ========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
    Posted by Jarrett on October 15 at 7:17 PM

  4. Using the New DateTime Support in .NET 3.5 via MVC & jQuery

    I've added New Global Date and Time Support  to BlogSvc by utilizing the new expanded support for date times with proper time zone support.  Some highlights in the MSDN documentation:

    The DateTimeOffset structure represents a date and time value, together with an offset that indicates how much that value differs from UTC. Thus, the value always unambiguously identifies a single point in time. A DateTimeOffset value is not tied to a particular time zone, but can originate from any of a variety of time zones. The TimeZoneInfo class makes it possible to work with dates and times so that any date and time value unambiguously identifies a single point in time. Taking advantage of time zone support in the .NET Framework is possible only if the time zone to which a date and time value belongs is known when that date and time object is instantiated.

    So the MSDN documentation is not clear on which class can make a date/time unambiguous.  However, the last sentence is the best clue.  We must capture both the UTC value and an originating time zone.

    For an ASP.NET MVC application we can add configuration to associate all date/times to our preferred time zone. 


    With this configuration, we can now write an HtmlHelper extension to display a DateTimeOffset in our preferred time zone.


    Call the extension method and pass it either a DateTimeOffset or a DateTime


    This will result in the follwing html:

    <abbr title='Tuesday, October 07, 2008 10:01 PM (GMT-06:00) Central Time (US &amp; Canada)'>10/7/2008 10:01 PM - CST</abbr>

    This gives an abbreviated date/time display at your preferred time zone.

    However, you may want to display time relative to the user browsing your website. There are two ways to accomplish this:

    • Ask and store each user's time zone
    • Automatically determine user's time zone using javascript

    The first option is commonly used with forums and requires the user to register and choose their preferred time zone. The second option makes much more sense for content websites (such as a blog) since it can occur automatically without registration.

    There is already a great plugin for jQuery that can display fuzzy times that are directly relative to the user.  It is called the Time Ago Plugin.  To use it, lets create another helper extension that utilizes a micro-format:


    This creates abbreviations in the html, that when activated through jQuery show times that will be automatically updated even after the user has loaded the page.


    This DateTime display is much more recognizable and personable to the casual user.

    Head on over to the BlogSvc website to download the code.

    Update: here is a bonus function that will allow you to format the date (with access to the time zone information) anyway you'd like.



    Call it like


    Posted by Jarrett on October 09 at 2:24 AM

  5. MVC is Cool

    image I've recently spent many late nights learning (by implementation) ASP.NET MVC and I'm very pleased with the new framework.  The old web forms model of programming was great for quick and dirty web apps but it really took too much control away from those developers who have a deep understanding of web technology. With MVC, it really lets web developers go back to their roots.  For example, you are no longer dealing with “asp” controls but directly with the classic html input controls.


    As part of my learning process, I converted BlogService over to Preview 5 release.  The conversion went smoothly.  For me, there was only a small learning curve as I’ve been tracking in MVC for a long time.  It is a quite popular topic right now especially with the announcement of jQuery being included out of the box with .NET.  How great!


    Check out the latest release of BlogSvc to see the code: BlogService MVC Release 0.6

    Posted by Jarrett on October 06 at 9:44 PM

© Copyright 2024