Author Archives: Larry House

Deploying ASP.Net MVC3 to Windows Azure

So the first question is can I run an ASP.Net MVC3 WebRole on Windows Azure?   The short answer is yes.  The long answer is, well long.  First off the tooling in Visual Studio 2010  does not directly support creating an ASP.Net MVC3 Webrole (pre SP1 at least, I haven’t beenable to install the SP yet so I can’t comment on the support with that installed, but I hear it will get better), so you have to do it manually.
To get things set up was pretty straight forward, just create your new ASP.Net MVC3 web application,
New ASP.Net MVC3 Application
and then add a new Windows Azure Project to the solution.
New Windows Azure Project
Now you will have to wire up the web role in your Azure Project.  To do this right-click on the Roles folder under your Azure Project and select Add | Web Role Project In Solution and select your project.
Assuming that you have done some work in your ASP.Net MVC3 Project and it is working and ready to deploy there is one more item you’ll need to address.   The Window Azure Hosted Services will not by default have all the assemblies you need to run your site.  To get around this you have a couple of options.  The way I did it was to make sure I had references to these assemblies (you may not since MVC apparently dynamically loads some of them at run time), and then for each one I went to properties and set CopyLocal to True.
Here is the list of assemblies I had to add.
  • System.Web.Mvc
  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Razor
  • System.Web.Helpers
  • System.Web.WebPages.Deployment

Your list may be slightly different.  If you miss one you will get a “Yellow Screen of Death” .

Error Sample

Just add that assembly to your list and try again…

Good Luck!

Microsoft Releases ASP.NET MVC 3.0, IIS Express, SQL Server Compact Edition 4.0, WebMatrix and more…

About a week ago (January 13th, 2011) Microsoft released a slew of developer tools to the web.

IIS Express 7.5

This is the item I am most excited about.  IIS Express is a free version of IIS 7.5 that can be used by developers when building web site.  It’s somewhere between Cassini (the ASP.Net development server) and a full blown IIS 7.5 install.  It provides support for SSL, URL Rewriting, and other IIS 7.x modules, while remaining under a 5mb download and running under non-administrator accounts.  It runs on Windows XP and higher and will run side by side with a full IIS install or Cassini.

Visual Studio 2010 SP1 (currently in Beta) will add support in Visual Studio for setting IIS Express as your default development server.

You can download IIS Express 7.5 and run it without SP1 for Visual Studio if you wish, but you will need to manually start the server.

Related Blog Posts:

Scott Guthrie: Introducing IIS Express

Scott Guthrie: VS 2010 SP1 (Beta) and IIS Express

ASP.NET MVC 3.0

Asp.Net MVC 3.0 is a very large release including:

  • The new ‘Razor’ View Engine which minimizes the number of characters used in you mark-up when data binding.
  • Improved JavaScript support.
  • Improved Validation.
  • Partial page output caching.
  • Better support for Dependency Injection and IOC Containers.

Get your hands dirty by downloading ASP.NET MVC 3.0 and trying out some demos on http://www.asp.net/mvc/.

NuGet

Nuget is a free, open source package manager that makes it easy for .NET developers to include open source libraries in any type of project from ASP.Net Web Forms to WPF.

Get the installer @ nuget.org and get started using all that open source goodness like NUnit, NHibernate, Castle.Windsor, and more.

Get more info:

Scott Hanselman’s Blog

Scott Guthrie’s Blog

Converting to Framework 4.0

We all would prefer to work with the latest technology. Unfortunately we often have applications that we built just yesterday using the last version of a framework, which is now so ancient history.  Luckily when it comes to .Net Applications Microsoft has done a great job of putting together conversion wizards to bring that old app up to the latest framework.

In this article I’ll walk through the relatively painless conversion process and then highlight a couple of things I have found to be pain points in the last couple of weeks as I have migrated applications to .Net 4.0 / Visual Studio 2010 from .Net 3.5 / Visual Studio 2008.

Converting an Application

To start you’ll need to have the latest version of Visual Studio 2010.  For the purpose of this article I’ll use Visual Web Developer 2010 Express to convert an application previous built in Visual Studio 2008.

vsopen

I usually make a copy of the project ahead of time in a separate folder before beginning,  That way if something goes wrong then nothing is lost.  (Although I have never had a conversion fail in an unexpected way.)

Go to File|Open Project … and browse to your solution file (*.sln) and open it.  The disk will churn a bit and you’ll be presented with the conversion wizard.

ConversionWizard

Click next and Visual Studio will ask you if you want to back things up first.  Since I am already working on a copy I choose no here.  I just don’t really like were Visual Studio puts the back up by default, which ends up being along side your project.

BackUp

Clicking next will bring you to the confirmation screen.

Finish

Now the disk will churn for a bit again and then you will get a dialog asking if you want to upgrade to framework 4.0 as well.

Convert

If you click no here your project will be converted to the 2010 Project format, but it will be left targeting the 3.5 framework (You can switch that later if you wish in the project properties).  If you click yes, the project file will be updated and the framework will be set to 4.0.  Pretty straight forward…

results

Once you choose an option things will churn a bit again and eventually you’ll be presented with a Conversion Report.

I did get a failure here, but it was expected.  The particular solution I converted had a number of projects in it including a couple of libraries, a web application, and a WinForms application.   Since I am opening this with Visual Web Developer the WinForms application did not load.  No problem, that was expected.

A Couple of Things to Note

After doing a few conversions I have run into a couple things you should know.

  1. In Framework 3.5 the Menu control renders by default as tables.  In 4.0 it renders by default as an unordered list.  The control has a property (RenderMode) that can be set to Default, Tables, or List.  So it’s your choice, you can set the value to Tables and move happily along, or convert things to work correctly as a List. If you choose to set it to List, I would, recommend setting the property to List explicitly.  I’ve seen things behave differently in different environments (IIS Versions) when set to default.
  2. There is a “Known Issue” in 4.0 where if you call __doPostback(‘foo’, ‘bar’) inside an AJAX Update Panel and the referenced control is not outside the Update Panel then nothing seems to happen at all.  The work around is to put a control with the specified name outside the Panel, however I have not tried this yet, In this particular case I opted to back off the 4.0 conversion for now because that change would have to be made in a number of complicated places in a critical application and it will require a large amount of testing to confirm the fix.  I converted this application to Visual Studio 2010, but left it at Framework 3.5.
  3. In the case when you have an ASP.Net web form that is allowing for example, HTML input, you may see an error something like: “A potentially dangerous Request.Form value was detected from the client…”.  We used to set RequestValidation=”false” on each page to get around this, but this does not in and of itself work in 4.0.  In 4.0 you will need to add an attribute(requestValidationMode=”2.0″) to the httpRuntime element in your web.config file to allow you to override the RequestValidation on the page level.  It looks something like this.

<httpRuntime requestValidationMode=”2.0″ />

You do still have to also set RequestValidation=”false” on the page as well.

More Information

There is a decent whitepaper on breaking changes in 4.0 on the ASP.Net web site at http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes

Windows Azure PDC10 Announcements

On the first day of PDC 2010 on Thursday Microsoft announced a slew of new features coming in Windows Azure including:

  • Remote Desktop (woot!)
  • A new Virtual Machine Role
  • Elevated Privileges
  • Full IIS
  • New Network functionality called Windows Azure Virtual Network.
  • New “Affordable” platform access options.
  • A new Silverlight based Portal for Managing deployments etc.

There were also announcements of new features coming in 2011.

Get all the details from the Windows Azure Team Blog or check out the PDC 2010 site.