Minggu, 23 Januari 2011

Announcing release of ASP.NET MVC 3, IIS Express, SQL CE 4, Web Farm Framework, Orchard, WebMatrix


I’m excited to announce the release today of several products:

  • ASP.NET MVC 3
  • NuGet
  • IIS Express 7.5
  • SQL Server Compact Edition 4
  • Web Deploy and Web Farm Framework 2.0
  • Orchard 1.0
  • WebMatrix 1.0

The above products are all free. They build upon the .NET 4 and VS 2010 release, and add a ton of additional value to ASP.NET (both Web Forms and MVC) and the Microsoft Web Server stack.

ASP.NET MVC 3

Today we are shipping the final release of ASP.NET MVC 3. You can download and install ASP.NET MVC 3 here. The ASP.NET MVC 3 source code (released under an OSI-compliant open source license) can also optionally be downloaded here.

ASP.NET MVC 3 is a significant update that brings with it a bunch of great features. Some of the improvements include:

Razor

ASP.NET MVC 3 ships with a new view-engine option called “Razor” (in addition to continuing to support/enhance the existing .aspx view engine). Razor minimizes the number of characters and keystrokes required when writing a view template, and enables a fast, fluid coding workflow.

Unlike most template syntaxes, with Razor you do not need to interrupt your coding to explicitly denote the start and end of server blocks within your HTML. The Razor parser is smart enough to infer this from your code. This enables a compact and expressive syntax which is clean, fast and fun to type.

You can learn more about Razor from some of the blog posts I’ve done about it over the last 6 months

Today’s release supports full code intellisense support for Razor (both VB and C#) with Visual Studio 2010 and the free Visual Web Developer 2010 Express.

JavaScript Improvements

ASP.NET MVC 3 enables richer JavaScript scenarios and takes advantage of emerging HTML5 capabilities.

The AJAX and Validation helpers in ASP.NET MVC 3 now use an Unobtrusive JavaScript based approach. Unobtrusive JavaScript avoids injecting inline JavaScript into HTML, and enables cleaner separation of behavior using the new HTML 5 “data-“ attribute convention (which conveniently works on older browsers as well – including IE6). This keeps your HTML tight and clean, and makes it easier to optionally swap out or customize JS libraries.

ASP.NET MVC 3 now includes built-in support for posting JSON-based parameters from client-side JavaScript to action methods on the server. This makes it easier to exchange data across the client and server, and build rich JavaScript front-ends. We think this capability will be particularly useful going forward with scenarios involving client templates and data binding (including the jQuery plugins the ASP.NET team recently contributed to the jQuery project).

Previous releases of ASP.NET MVC included the core jQuery library. ASP.NET MVC 3 also now ships the jQuery Validate plugin (which our validation helpers use for client-side validation scenarios). We are also now shipping and including jQuery UI by default as well (which provides a rich set of client-side JavaScript UI widgets for you to use within projects).

Improved Validation

ASP.NET MVC 3 includes a bunch of validation enhancements that make it even easier to work with data.

Client-side validation is now enabled by default with ASP.NET MVC 3 (using an onbtrusive javascript implementation). Today’s release also includes built-in support for Remote Validation - which enables you to annotate a model class with a validation attribute that causes ASP.NET MVC to perform a remote validation call to a server method when validating input on the client.

The validation features introduced within .NET 4’s System.ComponentModel.DataAnnotations namespace are now supported by ASP.NET MVC 3. This includes support for the new IValidatableObject interface – which enables you to perform model-level validation, and allows you to provide validation error messages specific to the state of the overall model, or between two properties within the model.

ASP.NET MVC 3 also supports the improvements made to the ValidationAttribute class in .NET 4. ValidationAttribute now supports a new IsValid overload that provides more information about the current validation context, such as what object is being validated. This enables richer scenarios where you can validate the current value based on another property of the model. We’ve shipped a built-in [Compare] validation attribute with ASP.NET MVC 3 that uses this support and makes it easy out of the box to compare and validate two property values.

You can use any data access API or technology with ASP.NET MVC. This past year, though, we’ve worked closely with the .NET data team to ensure that the new EF Code First library works really well for ASP.NET MVC applications. These two posts of mine cover the latest EF Code First preview and demonstrates how to use it with ASP.NET MVC 3 to enable easy editing of data (with end to end client+server validation support). The final release of EF Code First will ship in the next few weeks.

Today we are also publishing the first preview of a new MvcScaffolding project. It enables you to easily scaffold ASP.NET MVC 3 Controllers and Views, and works great with EF Code-First (and is pluggable to support other data providers). You can learn more about it – and install it via NuGet today - from Steve Sanderson’s MvcScaffolding blog post.

Output Caching

Previous releases of ASP.NET MVC supported output caching content at a URL or action-method level.

With ASP.NET MVC V3 we are also enabling support for partial page output caching – which allows you to easily output cache regions or fragments of a response as opposed to the entire thing. This ends up being super useful in a lot of scenarios, and enables you to dramatically reduce the work your application does on the server.

The new partial page output caching support in ASP.NET MVC 3 enables you to easily re-use cached sub-regions/fragments of a page across multiple URLs on a site. It supports the ability to cache the content either on the web-server, or optionally cache it within a distributed cache server like Windows Server AppFabric or memcached.

I’ll post some tutorials on my blog that show how to take advantage of ASP.NET MVC 3’s new output caching support for partial page scenarios in the future.

Better Dependency Injection

ASP.NET MVC 3 provides better support for applying Dependency Injection (DI) and integrating with Dependency Injection/IOC containers.

With ASP.NET MVC 3 you no longer need to author custom ControllerFactory classes in order to enable DI with Controllers. You can instead just register a Dependency Injection framework with ASP.NET MVC 3 and it will resolve dependencies not only for Controllers, but also for Views, Action Filters, Model Binders, Value Providers, Validation Providers, and Model Metadata Providers that you use within your application.

This makes it much easier to cleanly integrate dependency injection within your projects.

Other Goodies

ASP.NET MVC 3 includes dozens of other nice improvements that help to both reduce the amount of code you write, and make the code you do write cleaner. Here are just a few examples:

  • Improved New Project dialog that makes it easy to start new ASP.NET MVC 3 projects from templates.
  • Improved Add->View Scaffolding support that enables the generation of even cleaner view templates.
  • New ViewBag property that uses .NET 4’s dynamic support to make it easy to pass late-bound data from Controllers to Views.
  • Global Filters support that allows specifying cross-cutting filter attributes (like [HandleError]) across all Controllers within an app.
  • New [AllowHtml] attribute that allows for more granular request validation when binding form posted data to models.
  • Sessionless controller support that allows fine grained control over whether SessionState is enabled on a Controller.
  • New ActionResult types like HttpNotFoundResult and RedirectPermanent for common HTTP scenarios.
  • New Html.Raw() helper to indicate that output should not be HTML encoded.
  • New Crypto helpers for salting and hashing passwords.
  • And much, much more…

Learn More about ASP.NET MVC 3

We will be posting lots of tutorials and samples on the http://asp.net/mvc site in the weeks ahead. Below are two good ASP.NET MVC 3 tutorials available on the site today:

We’ll post additional ASP.NET MVC 3 tutorials and videos on the http://asp.net/mvc site in the future. Visit it regularly to find new tutorials as they are published.

How to Upgrade Existing Projects

ASP.NET MVC 3 is compatible with ASP.NET MVC 2 – which means it should be easy to update existing MVC projects to ASP.NET MVC 3.

The new features in ASP.NET MVC 3 build on top of the foundational work we’ve already done with the MVC 1 and MVC 2 releases – which means that the skills, knowledge, libraries, and books you’ve acquired are all directly applicable with the MVC 3 release. MVC 3 adds new features and capabilities – it doesn’t obsolete existing ones.

You can upgrade existing ASP.NET MVC 2 projects by following the manual upgrade steps in the release notes. Alternatively, you can use this automated ASP.NET MVC 3 upgrade tool to easily update your existing projects.

Localized Builds

Today’s ASP.NET MVC 3 release is available in English. We will be releasing localized versions of ASP.NET MVC 3 (in 9 languages) in a few days. I’ll blog pointers to the localized downloads once they are available.

NuGet

Today we are also shipping NuGet – a free, open source, package manager that makes it easy for you to find, install, and use open source libraries in your projects. It works with all .NET project types (including ASP.NET Web Forms, ASP.NET MVC, WPF, WinForms, Silverlight, and Class Libraries). You can download and install it here.

NuGet enables developers who maintain open source projects (for example, .NET projects like Moq, NHibernate, Ninject, StructureMap, NUnit, Windsor, Raven, Elmah, etc) to package up their libraries and register them with an online gallery/catalog that is searchable. The client-side NuGet tools – which include full Visual Studio integration – make it trivial for any .NET developer who wants to use one of these libraries to easily find and install it within the project they are working on.

NuGet handles dependency management between libraries (for example: library1 depends on library2). It also makes it easy to update (and optionally remove) libraries from your projects later. It supports updating web.config files (if a package needs configuration settings). It also allows packages to add PowerShell scripts to a project (for example: scaffold commands). Importantly, NuGet is transparent and clean – and does not install anything at the system level. Instead it is focused on making it easy to manage libraries you use with your projects.

Our goal with NuGet is to make it as simple as possible to integrate open source libraries within .NET projects.

NuGet Gallery

This week we also launched a beta version of the http://nuget.org web-site – which allows anyone to easily search and browse an online gallery of open source packages available via NuGet. The site also now allows developers to optionally submit new packages that they wish to share with others. You can learn more about how to create and share a package here.

There are hundreds of open-source .NET projects already within the NuGet Gallery today. We hope to have thousands there in the future.

IIS Express 7.5

Today we are also shipping IIS Express 7.5. IIS Express is a free version of IIS 7.5 that is optimized for developer scenarios. It works for both ASP.NET Web Forms and ASP.NET MVC project types.

We think IIS Express combines the ease of use of the ASP.NET Web Server (aka Cassini) currently built-into Visual Studio today with the full power of IIS. Specifically:

  • It’s lightweight and easy to install (less than 5Mb download and a quick install)
  • It does not require an administrator account to run/debug applications from Visual Studio
  • It enables a full web-server feature set – including SSL, URL Rewrite, and other IIS 7.x modules
  • It supports and enables the same extensibility model and web.config file settings that IIS 7.x support
  • It can be installed side-by-side with the full IIS web server as well as the ASP.NET Development Server (they do not conflict at all)
  • It works on Windows XP and higher operating systems – giving you a full IIS 7.x developer feature-set on all Windows OS platforms

IIS Express (like the ASP.NET Development Server) can be quickly launched to run a site from a directory on disk. It does not require any registration/configuration steps. This makes it really easy to launch and run for development scenarios. You can also optionally redistribute IIS Express with your own applications if you want a lightweight web-server. The standard IIS Express EULA now includes redistributable rights.

Visual Studio 2010 SP1 adds support for IIS Express. Read my VS 2010 SP1 and IIS Express blog post to learn more about what it enables.

SQL Server Compact Edition 4

Today we are also shipping SQL Server Compact Edition 4 (aka SQL CE 4). SQL CE is a free, embedded, database engine that enables easy database storage.

No Database Installation Required

SQL CE does not require you to run a setup or install a database server in order to use it. You can simply copy the SQL CE binaries into the \bin directory of your ASP.NET application, and then your web application can use it as a database engine. No setup or extra security permissions are required for it to run. You do not need to have an administrator account on the machine. Just copy your web application onto any server and it will work. This is true even of medium-trust applications running in a web hosting environment.

SQL CE runs in-memory within your ASP.NET application and will start-up when you first access a SQL CE database, and will automatically shutdown when your application is unloaded. SQL CE databases are stored as files that live within the \App_Data folder of your ASP.NET Applications.

Works with Existing Data APIs

SQL CE 4 works with existing .NET-based data APIs, and supports a SQL Server compatible query syntax. This means you can use existing data APIs like ADO.NET, as well as use higher-level ORMs like Entity Framework and NHibernate with SQL CE. This enables you to use the same data programming skills and data APIs you know today.

Supports Development, Testing and Production Scenarios

SQL CE can be used for development scenarios, testing scenarios, and light production usage scenarios. With the SQL CE 4 release we’ve done the engineering work to ensure that SQL CE won’t crash or deadlock when used in a multi-threaded server scenario (like ASP.NET). This is a big change from previous releases of SQL CE – which were designed for client-only scenarios and which explicitly blocked running in web-server environments. Starting with SQL CE 4 you can use it in a web-server as well.

There are no license restrictions with SQL CE. It is also totally free.

Tooling Support with VS 2010 SP1

Visual Studio 2010 SP1 adds support for SQL CE 4 and ASP.NET Projects. Read my VS 2010 SP1 and SQL CE 4 blog post to learn more about what it enables.

Web Deploy and Web Farm Framework 2.0

Today we are also releasing Microsoft Web Deploy V2 and Microsoft Web Farm Framework V2. These services provide a flexible and powerful way to deploy ASP.NET applications onto either a single server, or across a web farm of machines.

You can learn more about these capabilities from my previous blog posts on them:

Visit the http://iis.net website to learn more and install them. Both are free.

Orchard 1.0

Today we are also releasing Orchard v1.0.

Orchard is a free, open source, community based project. It provides Content Management System (CMS) and Blogging System support out of the box, and makes it possible to easily create and manage web-sites without having to write code (site owners can customize a site through the browser-based editing tools built-into Orchard). Read these tutorials to learn more about how you can setup and manage your own Orchard site.

Orchard itself is built as an ASP.NET MVC 3 application using Razor view templates (and by default uses SQL CE 4 for data storage). Developers wishing to extend an Orchard site with custom functionality can open and edit it as a Visual Studio project – and add new ASP.NET MVC Controllers/Views to it.

WebMatrix 1.0

WebMatrix is a new, free, web development tool from Microsoft that provides a suite of technologies that make it easier to enable website development. It enables a developer to start a new site by browsing and downloading an app template from an online gallery of web applications (which includes popular apps like Umbraco, DotNetNuke, Orchard, WordPress, Drupal and Joomla). Alternatively it also enables developers to create and code web sites from scratch.

WebMatrix is task focused and helps guide developers as they work on sites. WebMatrix includes IIS Express, SQL CE 4, and ASP.NET - providing an integrated web-server, database and programming framework combination. It also includes built-in web publishing support which makes it easy to find and deploy sites to web hosting providers.

You can learn more about WebMatrix from my Introducing WebMatrix blog post this summer. Visit http://microsoft.com/web to download and install it today.

Summary

I’m really excited about today’s releases – they provide a bunch of additional value that makes web development with ASP.NET, Visual Studio and the Microsoft Web Server a lot better.

A lot of folks worked hard to share this with you today. On behalf of my whole team – we hope you enjoy them!

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Link Rollup: New Documentation and Tutorials from Web Platform and Tools


Lots of cool stuff was released yesterday that I mentioned in the post ASP.NET MVC3, WebMatrix, NuGet, IIS Express and Orchard released - The Microsoft January Web Release in Context. The Web Platform & Tools Content Team has been working hard on new content and tutorials to get you up to date on all this fun new stuff.

Here's a link rollup from Wade's documentation team. Congratulations to Mike Pope, Tim Teebken, Rick Anderson, Tim Ammann, Keith Newman, Erik Reitan and Tom Dykstra on a great set of content.

Read on!

Web Matrix

Tim Amman (Lead Writer), Erik Reitan and Mike Pope (Editor)

ASP.NET Web Pages with Razor Syntax

Tim Teebken (Lead Programming Writer), Erik Reitan, and Mike Pope (Editor)

Intro to ASP.NET MVC 3 onboarding series.

Scott Hanselman and Rick Anderson collaboration and Mike Pope (Editor)

Both C# and VB versions:

MVC 3

Updated and new tutorials/ API Reference on MSDN

Rick Anderson (Lead Programming Writer), Keith Newman and Mike Pope (Editor)

Orchard

Keith Newman (Lead Programming Writer), Tom FitzMacken and Mike Pope (Editor)

NuGet

Tom Dykstra, Tim Teebken and Mike Pope (Editor))

Website Panel

Mike Pope provided editing support for the WebsitePanel Guide, authored by the Website Panel development team.

Enjoy!



© 2010 Scott Hanselman. All rights reserved.

Building a Self Updating Site Using NuGet


For those of you who enjoy learning about a technology via screencast, I’ve recorded a video to accompany and complement this blog post. The screencast shows you what this package does, and the blog post covers more of the implementation details.

A key feature of any package manager is the ability to let you know when there’s an update available for a package and let you easily install that update.

For example, when we deployed the release candidate for NuGet, the Visual Studio Extension Manager displayed the release in the Updates section.

Extension Manager Displaying NuGet as an Available Updates

Likewise, NuGet lets you easily see updates for installed packages. You can either run the List-Package –Updates command:

list-package-updates

Or you can click on the Updates node of the Add Package dialog:

updates-tab

This feature is very handy when using Visual Studio to develop software such as Subtext, an open source blog engine I run in my spare time. But I started thinking about the users of Subtext and the hoops they jump through to upgrade Subtext itself.

Wouldn’t it be nice if Subtext could notify users when a new version is available and let them install it directly from the admin section of the running website completely outside of Visual Studio? Why yes, that would be nice.

NuGet to the Rescue!

Well my friends, that’s where NuGet comes into play. While most people know NuGet as a Visual Studio extension for pulling in and referencing libraries in your project, there’s a core API that’s completely agnostic of the hosting environment whether it be Visual Studio, PowerShell, or other. That core API is implemented in the assemly, NuGet.Core.dll.

This assembly allows us to take advantage of many of the features of NuGet outside of Visual Studio such as within a running web site!

The basic concept is this:

  1. Package up the first version of a website as a NuGet package.
  2. Install this package in the website itself. I know, crazy talk, right?
  3. Add a custom NuGet client that runs inside the website and checks for updates to the one package that’s installed.
  4. When the next version of the website is ready, package it up and deploy it to the package feed for the website. Now, the users of the website can be notified that an update is available.s

I should point out a brief note about step #2, because this is going to be confusing. When I say install the package in the website, I mean to contrast that with installing a package into your Web Application Project for the website.

When you install a package into your Web Application Project, you use the standard NuGet client within Visual Studio. But when you deploy your website, the custom NuGet client within the live website will install the website package into a different location. In the example I’ll show you, that location is within the App_Data\packages folder.

The AutoUpdate Package

Earlier this week, I gave an online presentation to the Community For MVC (C4MVC) user’s group on NuGet. During that talk I demonstrated a prototype package I wrote called AutoUpdate. This package adds a new area to the target website named “Installation”. It also adds a nuspec file to the root of the application to make it easy to package up the website as a NuGet Package.

The steps to use the package are very easy.

  1. Install-Package AutoUpdate.
  2. In Web.config, modify the appSetting PackageSource to point to your package source. In my demo, I just pointed it to a folder on my machine for demonstration purposes. But this source is where you would publish updates for your package.
  3. In the Package Console, run the New-Package script (This creates packages up the website in a NuPkg file).
  4. Copy the package into the App_Data\Packages folder of the site.
  5. When you are ready to publish the next version as an update, increment the version number in the nuspec file and run the New-Package script again.
  6. Deploy the updated package to the package source.
  7. Now, when your users visit /installation/updates/check within the web site, they’ll be notified that an update is available and will be able to install the update.

The Results

Lets see the results of installing the AutoUpdate package and I’ll highlight some of the code that makes the package work. The following screenshot shows a very basic sample application I wrote.

home-page

The homepage here has a link to check for updates which links to an action within the area installed by the AutoUpdate package. That action contains the logic to check for updates for this application’s package.

Clicking on that link requires me to login first and then I get to this page:

update-available

As I mentioned in the steps before, I packaged up the first version of the application as a package and “installed” it into the App_Data folder.

That yellow bar above is the result of an asynchronous JSON request to see if an update is available. It’s a little redundant on this page, but I could have it show up on every page within the admin as a notification.

Under the Hood

Let’s take a look at the controller that responds to that asynchronous request.

public ActionResult Check(string packageId) {
var projectManager = GetProjectManager();
var installed = GetInstalledPackage(projectManager, packageId);
var update = projectManager.GetUpdate(installed);

var installationState = new InstallationState {
Installed = installed,
Update = update
};

if (Request.IsAjaxRequest()) {
var result = new {
Version = (update != null ? update.Version.ToString() : null),
UpdateAvailable = (update != null)
};
return Json(result, JsonRequestBehavior.AllowGet);
}

return View(installationState);
}




The logic here is pretty straightforward. We grab a project manager. We then grab a reference to the current installed package representing this application. And then we check to see if there’s an update available. If there isn’t an update, the GetUpdate method returns false. There’s a couple of methods here that I wrote we need to look at.



The first method very simply retrieves a project manager. I encapsulated it into a method since I call it in a couple different places.





private WebProjectManager GetProjectManager() {
string feedUrl = @'D:\dev\hg\AutoUpdateDemo\test-package-source';
string siteRoot = Request.MapPath('~/');

return new WebProjectManager(feedUrl, siteRoot);
}




There’s a couple things to note here. I hard coded the feedUrl for demonstration purposes to point to a directory on my machine. This is a nice demonstrations that NuGet can simply treat a directory containing packages as a package source.



For your auto-updating web application, that should point to a custom feed you host specifically for your website. Or, point it to the official NuGet feed and put your website up there. It’s up to you.



This method returns an instance of WebProjectManager. This is a class that I had to copy from the System.Web.WebPages.Administration.dll assembly because it’s marked internal. I don’t know why it’s internal, so I’ll see if we can fix that. It’s not my fault so please direct your hate mail elsewhere. Smile



What is the web project manager? Well the WebMatrix product which includes the ASP.NET Web Pages framework includes a web-based NuGet client for simple web sites. This allows packages to be installed into a running website. I’m just stealing that code and re-purposing it for my own needs.



Now, we just need to use the project manager to query the package source to see if there’s an update available. This is really easy.





private IPackage GetInstalledPackage(WebProjectManager projectManager,
string packageId) {
var installed = projectManager.GetInstalledPackages('AutoUpdate.Web')
.Where(p => p.Id == packageId);

var installedPackages = installed.ToList();
return installedPackages.First();
}




What’s really cool is that we can just send a LINQ query to the server because we’re running OData on the server, it’ll run that query on the server and send us back the packages that fulfill the query.



That’s all the code necessary to check for updates. The next step is to write an action method to handle the upgrade. That’s pretty easy too.





public ActionResult Upgrade(string packageId) {
var projectManager = GetProjectManager();
var installed = GetInstalledPackage(projectManager, packageId);
var update = projectManager.GetUpdate(installed);
projectManager.UpdatePackage(update);

if (Request.IsAjaxRequest()) {
return Json(new {
Success = true,
Version = update.Version.ToString()
}, JsonRequestBehavior.AllowGet);
}
return View(update);
}




This code starts off the same way that our code to check for the update does, but instead of simply returning the update, we call projectManager.UpdatePackage on the update. That method call updates the website to the latest version.



The rest of the method is simply concerned with returning the result of the upgrade.



Try it Yourself



If you would like to try it yourself, please keep a one big caveat in mind. This is rough proof of concept quality code. I hope to shape it into something more robust over time and publish it in the main package feed. Until then, I’ll post it here for people to try out. If there’s a lot of interest, I’ll post the source on CodePlex.com.



So with that in mind, give the AutoUpdate package a try




install-package AutoUpdate




and give me some feedback!



Running an ASP.NET MVC 3 app on a web server that doesn’t have ASP.NET MVC 3 installed


Last week we released several new web products – including ASP.NET MVC 3. We’ve had a bunch of great feedback and a ton of downloads since then.

One question a few people have asked me recently is: “My web hosting provider doesn’t yet support ASP.NET MVC 3 - any idea when they will install it?”

The good news is that you don’t need to wait for them to install anything on their web-servers. As long as your web hosting provider supports .NET 4, then you can build and deploy ASP.NET MVC 3 applications on it today – without the hosting provider having to do anything to enable it. The below post describes how you can enable this.

Some Background

We support two ways for you to install and use the assemblies that implement ASP.NET MVC 3 on a machine:

  1. Have the ASP.NET MVC 3 assemblies installed in a central place on a machine, and have web projects reference/use the assemblies from there
  2. Copy the ASP.NET MVC 3 assemblies into the \bin folder of your web project, and have your web project reference/use the assemblies from there

The first approach is the default approach we use with Visual Studio, and has the benefit of enabling us to easily service the ASP.NET MVC 3 assemblies using Windows Update (in the event of a bad bug).

The second approach is also fully supported, and has the benefit of not requiring ASP.NET MVC 3 to be explicitly installed on a machine in order for it to be used. Instead you can just copy/ftp your web application onto a server (with the ASP.NET MVC assemblies contained within the \bin directory of the application) and it will just work. You should use this second approach if your web hosting provider hasn’t explicitly installed ASP.NET MVC 3 yet on their servers.

Approach 1: GAC Based Referencing of ASP.NET MVC Assemblies

When you install ASP.NET MVC 3 on a machine, a number of assemblies are automatically registered in the GAC (global assembly cache) as part of the installation process. The GAC provides a central place that .NET assemblies can be installed and serviced (via Windows Update). Because it provides an easy way for us to update/service assemblies, ASP.NET MVC projects - by default - reference the assemblies that implement ASP.NET MVC 3 from it.

If you copy a vanilla ASP.NET MVC 3 project – that uses the default approach of referencing the ASP.NET MVC 3 runtime assemblies using the GAC – onto a machine that has not had ASP.NET MVC 3 installed on it, then you will see an error message like below when you run your application:

image

The above error indicates that one of the assemblies required to run ASP.NET MVC 3 from the GAC cannot be found. Installing ASP.NET MVC 3 on the machine will fix it and allow your application to be run.

Approach 2: \Bin Directory Based Referencing of ASP.NET MVC Assemblies

The alternative approach your projects can use is to distribute and reference the ASP.NET MVC 3 runtime assemblies from the \bin directory of your web application. The benefit of this approach is that you do not need to explicitly install ASP.NET MVC 3 on a machine in order to run your web application. Instead, you can just copy/ftp your web application onto an existing .NET 4 server and it will work. This approach works for both “full trust” and “medium trust” scenarios – which means it will even work with low-cost shared hosting offers. No addition registration/installation/action is required by the hosting provider in order to enable this.

Enabling your web project to “bin deploy” the ASP.NET MVC 3 assemblies is easy and only takes about 2 minutes to do. Here are the steps to follow:

Once configured for \bin based deployment, an application you build with ASP.NET MVC 3 will work on any web server that has .NET 4 installed on it. Just copy/ftp it up to the web-server and it will run. You don’t need the hosting provider to do anything to enable it – this is true even for low-cost shared hosting accounts.

Finding a ASP.NET Web Hosting Provider

You can browse the Windows Web Hosting Gallery to find good ASP.NET based Windows Hosting Providers (all of which support ASP.NET 4):

image

The Windows Web Hosting Gallery allows you to filter/browse hosting offers by different countries and service level offerings. It also allows you to easily filter by “Shared Hosting”, “Virtual Hosting” and “Dedicated Hosting” offers.

“Shared Hosting” refers to an offer where many customers run on a single web-server and you do not have admin access on the remote server. “Virtual Hosting” offers provide you with your own Virtual Machine image on a remote-server – typically with OS admin rights and remote terminal server access to manage it. “Dedicated Hosting” offers provide you an entire physical server, and also typically provide OS admin rights and remote terminal support to it.

The prices for Windows based web hosting are now very cost effective, and start from as little as $2.75/month for a shared hosting offer and $23/month for a virtual hosting offer. All of the above offers are capable of running ASP.NET MVC 3 using the \bin deployment approach.

Summary

You can deploy ASP.NET MVC 3 based applications to any web-server that has .NET 4 enabled on it – without having to wait for the hosting provider to explicitly install ASP.NET MVC 3 on it. Simply use the steps above to convert your project to use \bin based deployment of the ASP.NET MVC 3 assemblies, and then you can copy your application onto any ASP.NET 4 based server and it will just work.

Hope this helps,

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

NuGet Logo Stickers


Last night I got a little treat in the mail from the kind folks at StickerMule. I really appreciate how they support open source projects with such great stickers.

NuGet-Stickers-550x365 Look at all those little NuGets!

Just in time as I have a few events I’ll be going to where I can hand some out such as Web Camps Argentina/Brazil, the MVP Summit, and if I’m selected, Mix 2011.

After that, I need to figure out the best way to give the rest out since I won’t be travelling a whole lot this year. We’ll need to have a Nerd Dinner or something. I’ll give some to Scott Hanselman since he travels a lot too.

Microsoft Web Farm Framework 2.0


The IIS team recently published the Microsoft Web Farm Framework 2.0 release to the web. You can learn more about it and download the final V2 release of it here.

What is the Web Farm Framework?

The Microsoft Web Farm Framework is a free, fully supported, Microsoft product that enables you to easily provision and mange a farm of web servers. It enables you to automate the installation and configuration of platform components across the server farm, and enables you to automatically synchronize and deploy ASP.NET applications across them.

It supports integration with load balancers, and enables you to automate updates across your servers so that your site/application is never down or unavailable to customers (it can automatically pull servers one-at-a-time out of the load balancer rotation, update them, and then inject them back into rotation).

A few months ago I posted a tutorial about the Microsoft Web Farm Framework that demonstrates how to configure and use it. You can read my tutorial about it here.

New Features Added to the Final V2 Release

This week’s RTW release includes several additional features that were not in the previous beta. They include:

  • Workflow Builder can be used to define and schedule custom tasks that can be run on all servers in the farm. The tasks can be scheduled to run periodically or can be started manually by an administrator. An example of such task could be a msdeploy command to partially sync web site content.
  • Windows Credential Store support enables you to store the administrator credentials used for server provisioning in a secure Windows Credential Store. This enables an added layer of security when dealing with credentials with the Web Farm Framework.
  • Third party load balancers support via Web Farm Framework extensibility. It is now possible to configure the Web Farm Framework to integrate with hardware load balancers instead of relying on the (free) IIS Application Request Routing module.
  • Improved support for advanced MSDeploy operations. More MSDeploy features can now be used with the Web Farm Framework for advanced deployment scenarios.
  • Improved support for syncing large amount of files. Several issues related to syncing large amounts of files across web farm nodes have been fixed between the beta and today’s release.

This week’s release also includes many bug fixes and performance optimizations.

Learning More

Visit the below links to learn more about the Web Farm Framework 2.0 release:

Summary

The Microsoft Web Farm Framework simplifies the provisioning and deployment of your web server infrastructure – both the servers themselves, as well as the web applications and sites you run on top of them.

The Web Farm Framework enables a smoother continuous deployment workflow. It also makes it easy to seamlessly scale your infrastructure by adding servers to it without additional management overhead. Best of all it is available at no extra cost and works with all editions of Windows Server.

Hope this helps,

Scott

P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

Sprechen Sie ASP.NET MVC?


Ni hao ma!

Hot on the heels of the RTM release of ASP.NET MVC 3, we now have localized versions of ASP.NET MVC in 9 languages! The installation links within the Web Platform Installer was updated. If you want to download the installer yourself, you can go to the English download page and select your language or click on one of the nine languages below:

If you speak one of these nine languages, you can now develop with ASP.NET MVC in your native language. Salud!