Odds and Ends, May 2011 05 May 2011 at 13:47

Symbolic links in Windows: http://technet.microsoft.com/en-us/library/cc753194(WS.10).aspx this was weird.  I was moaning to Rohland about how I missed have symlinks from Linux, but Id never bothered to research the alternative in Windows, assuming that Shortcuts were all we have.  It turns out, you CAN make sybmbolic links in Windows.

Sick of Windows 7 copying? http://www.codesector.com/teracopy.php I love this tool.  It also queues copying requests so you dont end up with a hard drive going back and forth like a scratch record.

Precompiling Razor views: http://odetocode.com/blogs/scott/archive/2011/02/16/notes-on-building-razor-views.aspx this is awesome.  Set up your Debug version to not precompile views, and set up an automated build to precompile views in Release mode at a regular interval to catch any issues in your views caused by refactoring.

PNGOUT: http://advsys.net/ken/utils.htm this is a FREE tool that reduces the size of PNG files by 5 30%.  Running this on all images for presentations, blog posts and web sites is a pretty good idea!

Dapper: http://code.google.com/p/dapper-dot-net/ this looks SO useful for smaller projects.  Its being used on stackoverflow.com though maybe not such small projects too!

IIS Compression: Excellent post by Rick Strahl with regards to setting up compression in IIS7: http://www.west-wind.com/weblog/posts/2011/May/05/Builtin-GZipDeflate-Compression-on-IIS-7x

MVC3 Deployment Nightmare 06 May 2011 at 17:07

I had a freaking nightmare deploying an MVC3 app today.  Seems simple.  Database was up and running.  The code was deployed and had been tested on our local systems.  I deployed via our amazing SVN deployment process, and published on the live server.  Permissions applied automatically, all the files appeared all was good in the world.  Until I loaded up the site in my browser and hit

Infinite Redirects

Fan-freaking-tastic.  Double-check the Web.config.  Fine.  Double-check the IIS mappings.  Fine. This ruined my day.  To cut a long story short: this all boils down to conflicts between the versions of MVC3 binaries between RC1 and RC2.  If you search on the web you will find numerous references to issues with the get_viewBag() call, and to be honest, I didnt have to time to fully understand WHY this is such a cockup.

Either way, the solution I finally came up with was to UNINSTALL MVC3 on the web server, manually add the .dll references to our project, and force "Copy Local".

http://www.tugberkugurlu.com/archive/deployment-of-asp-net-mvc-3-rc-2-application-on-a-shared-hosting-environment-without-begging-the-hosting-company

The DLLs that must be referenced:

  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Razor
  • System.Web.Helpers
  • System.Web.WebPages.Deployment (If you are deploying MVC RC 2, this assembly is necessary to deploy)
  • System.Web.Mvc

Make sure these copy locally to your bin folder (Right click, Properties, Copy Local = true)

This sorted out that bug.  Enter the next issue: The type or namespace name 'WebMatrix' could not be found (are you missing a using directive or an assembly reference?).  WTF!?

Web Matrix Agony Part 1

MVC3 RC2 has a bug where some of the source files have "using WebMatrix" references in them. As such, even though you don't need them, your project will not run without a reference to WebMatrix, which is annoying.

The obvious solution is to add these as a reference, but I tried that and it fails because WebMatrix requires an initialisation call in the Global.asax. Bummer.  I redeployed, and my error message now changed to

You must call the "WebSecurity.InitializeDatabaseFile" or "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class.

EFF THIS.

Web Matrix Agony Part 2

To get around this, in your global.asax make sure you add the following code at the bottom of the file:

namespace WebMatrix.Data { internal class Ignore { } }
namespace WebMatrix.WebData { internal class Ignore { } }

Reference: http://stackoverflow.com/questions/4146545/razor-helper-in-mvc-3-rc

This works as the statements in the MVC3 source binaries are only using statements!  I added these lines to the end of my Global.asax with a big comment about how much I hate the world and how much those 2 lines of code REALLY NEED TO STAY; removed the WebMatrix references I had added earlier, published, and redeployed.

And everything started working.