Silverlight Hack

Silverlight & related .NET technologies

About Me

Welcome to Silverlighthack.com.  This is a site where you can find many articles on Silverlight, Windows Phone 7 and .NET related technologies.  

My name is Bart Czernicki.  I have been working with computers since 1988 and have over 12 professional years in the IT field focusing on architecture, technology strategy and product management.  I currently work as a Sr. Software Architect at a large software development company.

Below is the cover of my new book that shows how Silverlight's unique RIA features can be applied to create next-generation business intelligence (BI 2.0) applications.

Silverlight 4 Business Intelligence Soft 

Contact: bartczernicki@gmail.com

View Bart Czernickis profile on LinkedIn

NONE of the comments or opinions expressed here should be considered ofmy past or current employer(s).  The code provided is as-is without anyguarantees or warranties.

Step by step instructions to deploy ASP.NET MVC 3 to Windows Azure

Abstract:  This article will show you the steps to overcome the lack of  Visual Studio 2010/Azure SDK tooling to deploy ASP.NET MVC 3 as a web role to the Azure cloud.  As of the time this article was written, there are many articles out there that overcomplicate the steps and some are even outdated with the new Azure 1.4 SDK release.  This article will allow you to work with the full ASP.NET MVC 3 tooling.  This article will be relevant until Microsoft releases an update to the Visual Studio 2010 tooling for Azure (probably not until the Azure 1.5 SDK).  The Visual Studio 2010 project/source code is included below.

10/01/2011 Update: The latest Windows Azure SDK (September 2011 Update) now includes ASP.NET MVC 3 by default.  However, if you are interested in including ASP.NET MVC4 in Azure, these steps can be followed below (with some changes).

For example, this week a Microsoft employee Avkash Chauhan posted an article called "ASP.NET MVC3 Web Role Deployment in Windows Azure (SDK 1.4) - Detailed steps and Full Sample".  While the article is correct and the process outlined will work, it overcomplicates the steps necessary and there are some bugs in his solution (i.e. you do not get the MVC 3 tooling support, since it is a ASP.NET MVC 2 web role).

Deploying ASP.NET MVC 3 to Azure 1.4 should not include so many steps.

 

Steps to Deploy an ASP.NET MVC 3 web role to the Azure Cloud

The list below are the high level steps that that this article will follow.

  1. Create a new ASP.NET MVC 3 project
    • this can be an Internet or Empty application (or an existing ASP.NET MVC 3 project)
  2. Add a Windows Azure Cloud project
  3. Add the Azure Web Role components to the ASP.NET MVC 3 Project
  4. Add the ASP.NET MVC 3 Assemblies to the bin Folder
    • Deploying via the new Azure 1.4 start up tasks is another method
  5. Publish to Windows Azure
Note: You will need to have some experience with Windows Azure, since I do not cover publishing to the Azure cloud (creating certificates, management console, remote desktop etc.).  You will also need:
  • Visual Studio 2010 SP1
  • ASP.NET MVC 3 with tools update (Released in May 2011: http://www.asp.net/mvc)
    • NuGet Package Manager
  • Azure 1.4 SDK installed
  • Active Windows Azure hosted service account (there is a promotion going on to receive Windows Azure for FREE until September 30th 2011, much better than the FREE 30 day trial if you just want to test things out or run a small blog: http://www.microsoft.com/windowsazure/free-trial/

1) Create a new ASP.NET MVC 3 Project

  1. Open Visual Studio 2010 (as an Administrator)
    • The Azure Cloud emulator needs to run in elevated privaledges
  2. Inside Visual Studio 2010, go to File -> New Project
    • Select "ASP.NET MVC 3 Web Application"
    • I named the project "AspNetMVC3DeployToAzure" *you can call it whatever you like)
    • Select "Internet Application" from the next dialog windo
      • Note that we will not be deploying the ASP.NET membership provider to SQL Azure (that will be for another time)
      • Just as long as you do not click Log On the application will function correctly
  3. If you build the application and debug it, you should see the generic ASP.NET MVC 3 startup screen
 
 

2) Add a Windows Azure Cloud Project

  1. In the Visual Studio 2010 Solution Explorer, right-click on the AspNetMvc4DeployToAzure solution and select Add -> New Project... 
  2. In the New Project Dialog, 
    • select "Cloud" from the Installed Templates
    • select the "Windows Azure Project"
    • I named the project "WindowsAzureAspNetMvc3Deploy" (you can name it whatever you prefer)
  3. In the next dialog, do NOT select any Windows Azure roles.  Leave it empy and click OK.

 

3) Add the Azure Web Role components to the ASP.NET MVC 3 Project

  1. In the Solution Explorer, highlight the ASP.NET MVC 3 project by clicking on it (this will tell Visual Studio the context you are in(
  2. In Visual Studio 2010 (this step will only work if the ASP.NET MVC 3 project is highlighted) go to Tools -> "Library Package Manager" -> "Add Library Package Reference..."
  3. Click "Online" to search the available packages Online
  4. Type in "windowsazure" all one word NO spaces
  5. Select the WindowsAzure.WebRole package and click Install.  Close the dialog after you are done (VS 2010 will ask you to reload the project...click OK) The following changes will be made to the ASP.NET MVC 3 Project:
    • The package will add the necesary Windows Azure SDK 1.4 assemblies
    • The package will make changes necessary in the web.config for Windows Azure
    • The package will add a class that facilitates the new Azure SDK 1.4 change for performign a task when the role is deployed
  6. In the Solution Explorer, right-click on the Roles folder of the Windows Azure project. (this will tell our Windows Azure cloud project that we want to associate to the ASP.NET MVC 3 web role)
    • Select Add -> "Web Role Project in Solution..."
      • In the previous step, we ran the NuGet package that "converted" our traditional ASP.NET MVC 3 application to a web role by adding all the necessary assemblies.  Therefore, this step is telling Azure that we want to add an existing Web Role from our current solution.
  7. In the "Associate with Web Role" dialog, click OK (as we only have one available project)
  8. Your solution should now look like the screen shot below.
    • Note that we have additional Azure assemblies referenced in the ASP.NET MVC 3 project, we have a new class WebRole.cs, the web.config has Azure elements in it and inside the Azure cloud project we have a new web role added
.
  • You can now buiild and debug the solution.  If you did everything properly, this will launch the Windows Azure emulator and run the application.

4) Add the ASP.NET MVC 3 assemblies to the bin folder

Note: the emulator is just an emulator, so it is still utilizing resources on your workstation (i.e. ASP.NET MVC 3, Web Matrix assemblies).  In a real Azure Virtual Machine, you will ONLY have the basic .NET 4.0 assemblies (Microsoft only keeps the VMs to a bare minimum).  Therefore, we need to add those assemblies as part of the deployment into Azure VM.  

Note:  An alternative approach is to utilize the ASP.NET MVC 3 installer as a Azure  start up task (each time the VM is restarted or re-provisioned in case of an error or recovery process) or manually set each assembly to "Copy Local" to True.

 

  1. In the ASP.NET MVC 3 Tools Update Microsoft provides a very easy way to add all the required ASP.NET MVC 3 assemblies automatically for bin deployment. (thanks to Mike Brown from http://azurecoding.net/ for pointing this out).
  2. Right-click on the ASPNetMvc3DeployToAzure MVC 3 project and select "Add Deployable Dependencies..."
  3. Select ASP.NET MVC checkbox and click OK
    • This will add the necessary ASP.NET MVC 3 dependency assemblies.
  4. You Solution Explorer in Visual Studio should look like this after adding the ASP.NET MVC 3 Dependency assemblies.
  5. :
 

5) Publish to Windows Azure

 

  1. Now you are ready to publish to Windows Azure.  Right-click on the Windows Azure project and select Publish.  Select your Azure credentials and storage information.
  • Note: If you do not have the Azure hosted service, storage or credentials set up you will have to create it.  Step by step instructions can be found here (Microsoft has better instructions than I will write on this)
    • I highly recommed you also select the "Enable Intellitrace for .NET 4 Roles".  This will show you any errors that you get if you don't have the proper ASP.NET MVC 3 assemblies installed.  Here is a good article on how you can view the IntelliTrace logs: http://www.nickharris.net/2010/09/how-to-enable-intellitrace-on-windows-azure/.  For exampe, if you forget to enable "Copy Local" to true for the System.Web.Mvc.dll the Azure publish process will cycle and you will not know why.
  • If you forget a certain assembly, you will also get an error like this (if you turn off custom errors in the web.config)
 

Visual Studio 2010 Source Code For Project

 
This source code for this project includes some minor changes unrelated to the steps above:

AspNetMVC3DeployToAzure.zip (13.85 mb)

  • in the web.config I turned custom errors off, so you can see the errors if you receive any in deploying
  • I changed the Windows Azure instance to be "Extra Small", this way you get charged less playing with this and it is covered under the FREE Windows Azure trial
  • I changed the OS family to 2 in the Windows Azure configuration, so that we receive a Windows Server 2008 R2 VM...not sure why that is not the default (?) 
 
 
Summary 
 
In this article, I hope you learned how to deploy an ASP.NET MVC 3 application to the Azure cloud easily.  The key things to remember are:
  • using the WindowsAzure.WebRole NuGet package to convert your ASP.NET MVC 3 application to a web role
  • Associating the ASP.NET MVC 3 project with the Windows Azure Cloud project
  • Using the new "Add Deployment Dependencies.." feature in the ASP.NET MVC 3 Tools Update to deploy all the required ASP.NET MVC 3 assemblies
In the future, Microsoft will no doubt make this process easier and include ASP.NET MVC 3 tooling for Azure deployment.
 
 
Posted: May 15 2011, 09:06 by Bart Czernicki | Comments (3) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: ASP.NET MVC | ASP.NET MVC | Azure | Azure
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Five Things that HTML5 Video Currently will not do, but Silverlight or Flash will

Abstract:  This article will cover 5 pieces of functionality that are not built-in currently into the HTML5 video specification that Silverlight and Flash can solve.  This article covers potential workarounds and how HTML5 will handle these limitations in the future.  Note a great deal of conent of this article comes from Nigel Parker's talk at MIX 2011 "Things You Need To Know To Start Using <video> and <audio> Today".

Note: this post is meant to be informational about HTML5 video compared to Silverlight/Flash. Even if you don't like Silverlight or Flash, I hope you learn something by reading sme of the current limiations of HTML5 video. For more info check out Robert Reinhardt's article (<Hype>Flash video is coming to iPad.</Hype><Reality>Yet another streaming solution will be available for H.264 to iOS.</Reality>) that covers the topic from another perspective.

Update 10/01/2011: Updated some information below, however the content in this article is still current.

1) Digital Rights Management (DRM) - Cannot protect video content over HTML5

The HTML5 does not and will not ever include Digital Rights Management.  One of the owners of the the HTML5 draft is quoted as saying: "If we provided DRM in the HTML5 draft, it would be hacked in 2 days".  Therefore, content that includes sports, Hollywood movies, tv shows etc. will never be provided over HTML5 video legally.  This can be confusing for some people, because you hear many people post blogs or tweets "Youtube is going full HTML5".  This is partly true.  User content on Youtube will be HTML5, but you will never see copyright music videos or movies on Youtube surfaced over HTML5 containers or codecs.  

Workaround: None (use Silverlight or Flash)

Probability of being included in future HTML5 draft: None

2) No Smooth Streaming or Adaptive Streaming

The HTML5 draft/spec does not include conventions for smooth streaming/adaptive streaming.  Silverlight with IIS 7.x Smooth Streaming extensions can provide this for you.  There do exist third-party solutions for HTML5 adaptive streaming.  For example, Apple's HTTP Live Streaming (HLS).  However, this is not part of the current HTML5 draft/spec.

There is work currently being done to take an adaptive streaming recommendation to the HTML5 council for approval.  The data visualization below (taken from w3.org ) shows this in better detail:

 

Workaround: Use Silverlight, Adobe Flash or Apple's native solutions

Probability of being included in future HTML5 draft: Very High
 
3) No Standard Video Codecs for HTML5
 
The HTML5 draft/spec does not include an explicit definition of what codec should be used for surfacing HTML5 videos.  This has been a contraversial decision that has led to developers of browsers to determine which codecs they allow to play on their browser.  The main contraversy surrounds the use of a proerietary codec (H.264), which both Apple and Microsoft support.  Conversely, the Mozilla, Opera and Google browsers have rallied around an open-source encoder called WebM and Ogg.  Neil Parker's slide from his MIX 2011 talk shows a great breakdown of the codec support in current browsers: 
 
 
Workaround: In the HTML5 markup, you can provide multiple different encoding sources and resolutions targeting mobile or desktop/laptop clients.  Furthermore, you can also fallback to Silverlight or Flash if the browser is not HTML5 compliant.  It is up to the developer to provide all these fallback scenarios.  This is equivelant to providing different CSS or JavaScript depending on browser support.
 
Probability of being included in future HTML5 draft: Very Low (the HTML5 spec would have to change their decision and prescribe a default codec for all HTML5 video tags)
 
4) Full Screen Support 
 
HTML5 currently does not support full screen video.  (Update 10/01/2011) For an example, check out a video from the Microsoft BUILD Conference.  While viewing the video in HTML5 format, you cannot view it in fullscreen (in Silverlight you can).  To me it is kind of a big deal especially when you are looking at source code on a partial screen.
This is not a technology problem or not possible to implement in browsers, however the current debate of full screen HTML5 video centers around what keyboard functions are available and what happens when you exit full screen mode.  The main reason for this is security:
 
"User agents should not provide a public API to cause videos to be shown full-screen. A script, combined with a carefully crafted video file, could trick the user into thinking a system-modal dialog had been shown, and prompt the user for a password. There is also the danger of "mere" annoyance, with pages launching full-screen videos when links are clicked or pages navigated. Instead, user-agent specific interface features may be provided to easily allow the user to obtain a full-screen playback mode." 
 
Note: Silverlight 4 and Adobe Flash 10.2 allow a user with dual monitors to play a video in full screen HD while the other monitor remains responsive to full user input.  It will be interesting how HTML5 browsers solve this, as this could be a potential security problem (since everything to manipulate in HTML5 is done via JavaScript libraries).  Example here of Silverlight 4 dual monitor pinning. 
 
Workaround: Use the VideoFullScreen.js provided by Martin Rauscher: here
 
Probability of being included in future HTML5 draft: High (HTML5 draft spec needs to explicitly define how browers interact with full screen.  For example, initially Silverlight 3 allowed full screen video but limited the keyboard functionality for the same security reasons as mentioned above).
 
5) No Standard Conventions/Look and Feel
 
One of the nice thing about plug-ins like Silverlight or Flash is that you essentially publish your video and let Microsoft or Adobe handle all the compatibility implementations across browsers or operating systems.  For HTML5 video tags it is up to the browsers to implement this themselves.  For example, Neil Parker had a great slide that showed an HTML5 video with a rounded corner border applied.  These are the results: 
 
 
 
This also includes the standard controls that are rendered with each video by different browsers.
 
Workaround: You can create a custom HTML5 video player control or use one of the third party ones.  Some are open source and some you can purchase.
 
Probability of being included in future HTML5 draft: Some of this already is.  It is up to the browser developers to fix their CSS and HTML5 video implementations (or use HTML polyfill patterns).  However, the HTML5 spec is not going to perscribe the very detailed looked of the progress bar of the video control (Note: in Silverlight and Flash you get a consistant look and feel across the browsers since Microsoft and Adobe control this; although you can create your own custom video players as well).
 
Summary 
 
In summary, the current HTML5 specification and implementations for video have some gaps.  It is important to note the current limitations of HTML5 video, especially with DRM.  A naive web developer wil be surprised to know that they can't just put a video tag with an encoded video and have it work as expected across all browsers just like Flash/Silverlight do.  There are some workarounds & solution available to provide Flash-like video.  However, the naive approach that HTML5 solves everything about video for you because its "new" or "better" will quickly get you in trouble.
 
Posted: Apr 16 2011, 13:05 by Bart Czernicki | Comments (10) RSS comment feed |
  • Currently 3.142857/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: HTML 5 | HTML5 | Silverlight
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

ASP.NET MVC 3 Intranet Template with "This resource cannot be found" and User.Identity.Name is blank Error

ASP.NET MVC 3 Tools refresh recently was released and it includes a new Intranet Visual Studio project template.  This template is basically an ASP.NET MVC 3 template with Windows Authentication enabled (the Internet Application template uses forms based authentication).

 
I was recently playing with this template and it worked fine in development and even using the IIS 7.x Express Web Server.  However, when I deployed to a real Windows Server 2008 R2 application I saw this "The resource cannot be found" error:
 
 
So what is going on?  Notice (from the screenshot above) that we are being redirected to .../Account/Login.  This is a clue that the login/authentication is failing. The controller for login is throwing the error.  
 
If you explicitly actually type in /Home/About you will actually get a rendered page below.  Notice in the top right corner all you see is an exclamation point.  The @User.Identity.Name code in the _Layout.cshtml is blank/NULL and causing the error (shown below that is why you only see "Welcome !"). 
 
 
Why is Windows Authentication not working?  It looks to me that this is a bug in the ASP.NET MVC 3 Intranet template....I stumbled upon this by chance, by going through the "known issues" section in the ASP.NET MVC 3 release notes.  It mentions that we should add this line (<add key="enableSimpleMembership" value="false" />) to the web.config if we are upgrading from an ASP.NET MVC 2 application.  This has NOTHING to do BTW with Windows Authentication and I tried adding that key in web.config by chance and it properly authenticated me.
 
After adding the key (and restarting the application pool), ASP.NET MVC 3 properly is able to grab the identity of the user via Windows Authentication.  Basically the appsettings section of the web.config should look like this now:
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="enableSimpleMembership" value="false" />
  </appSettings> 
 
If you receive a "This Resource Cannot be Found" error or the User.Identity.Name is blank or IsAuthenticated is false for an ASP.NET MVC application ensure:
  • Windows Authentication is turned on in web.config (IIS 6 and 7)
  • You are using the Integrated pipeline mode in the application pool (IIS 6 and 7)
  • All the wildcard mappings and ISAPI settings are properly set up (IIS 6)
  • Add the key: <add key="enableSimpleMembership" value="false" /> to the appSettings section
  • If you have Kerebos/NTLM etc authentication, make sure it is configured correctly in IIS
I hope this article helped anyone who is going through this annoying issue, as I spent several hours trying to figure it out myself.  It seems like Microsoft needs to update their ASP.NET MVC 3 Intranet template to include this line for production scenarios.
Posted: Apr 13 2011, 16:38 by Bart Czernicki | Comments (0) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .net | ASP.NET MVC
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

IaaS, PaaS and SaaS Terms Clearly Explained and Defined

I love it when semi-abstract terms and sometimes confusing technologies have an easy way to describe them in a terse/quick manner.  I found a great explanation from the "Windows Azure Platform: Cloud Development Jump Start" series in the first video (the video series is available both on iTunes and Zune and it covers the latest 1.3.x version of the SDK).  The series is provided free of charge.  Below are a couple of slides from the presentation:

Easy to Understand one-word descriptions of each term (i.e. IaaS means host) 

 
 
Data Visualization of Vendor Management Responsibility of Services
 
I really like the last slide, because it clearly breaks down hierarchy of software layers into what is each vendor service (IaaS, PaaS and SaaS) is responsible for and what you are responsible for.  Also in the video one of the speakers (Manu Cohen-Yashar) breaks each service down by the "unit you are gaining" from the service:
  • IaaS - the unit you are gaining is a computer/server. Therefore IaaS is essentially a "physical server box".  An example of this would be going to RackSpace or SoftLayer and leasing a physical box from them.  The vendor manages the networking, hard drives (if they fail), hardware of the box, virtualization O/S (if the box is virtualized).  You can remote desktop to the box and you manage everything else (shown in the screenshot above). Windows Azure provides IaaS in the form the VM Role (you upload a Windows Server 2008 R2 image and manage the server yourself).
  • PaaS - the unit you are gaining is an application/framework.  Therefore PaaS is a "hosted application/framework/tools that you can leverage to build something on.  That application is configured on IIS/SQL Server etc and runs on a hardware/virtual system that the vendor manages. An example of PaaS would be Windows Azure (excluding the VM Role) services like web role, worker role, Reporting Services etc.
  • SaaS - the unit you are gaining is business functionality.  For example, Gmail is a type of a SaaS mail provider because you don't have to manage any service yourself and its all done by the vendor (Google in this example).
I really like the clear examples and distinct definitions that are made in the videos.  Hopefully, you can use these examples in explaining this to your boss or a non-technical person.  I highly recommend you check out the "Windows Azure Platform: Cloud Development Jump Start" series if you are interested on learning about Azure or gain general information on the cloud.  
Posted: Feb 27 2011, 13:23 by Bart Czernicki | Comments (0) RSS comment feed |
  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Azure
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us