Installing the Mobile Client Application

This section describes how Tailspin arranges for users to install the mobile client application on their Windows Phone 7 devices. Users can only install applications on their devices from the Windows Marketplace, so Tailspin must first make sure that the application is available there.

Overview of the Solution

To make it easy for users to find, download, and install the mobile client application, Tailspin wanted to provide a link to the mobile client installer from the public Tailspin website with which users may already be familiar. Tailspin provides a Windows Phone 7-friendly page at the same address as the public Tailspin website. Accessing the site with Microsoft® Internet Explorer® from a desktop device shows a list of available surveys; alternatively, accessing the site with Internet
Explorer from a Windows Phone 7 device shows a link to the installer for the mobile client application.

The developers at Tailspin used a Model-View-Controller (MVC) view engine to display a different page based on the type of device making the request.

For more information about MVC, see “ASP.NET MVC 2” on MSDN® (http://msdn.microsoft.com/en-us/library/dd394709.aspx).

Inside the Implementation

Now is a good time to walk through the code that implements the Windows Phone 7 web page in more detail. As you go through this section, you may want to download the Microsoft® Visual Studio® development system solution for the Tailspin Surveys application from CodePlex (http://go.microsoft.com/fwlink/?LinkId=205602).

To render different pages at the same address based on the type of device, the Tailspin web application uses the WebForm ViewEngine class in the MVC namespace. The application creates a new view engine of type MobileCapableWebFormViewEngine in the Global.asax.cs file. The following code example shows the MobileCapableWebFormViewEngine class in the TailSpin.Web. Survey.Public project.

C#

namespace TailSpin.Web.Survey.Public.Extensions
{
using System;
using System.Web.Mvc;
public class MobileCapableWebFormViewEngine : WebFormViewEngine
{
public override ViewEngineResult FindView(
ControllerContext controllerContext, string viewName,
string masterName, bool useCache)
{
ViewEngineResult result = null
if (this.UserAgentIs(controllerContext, “IEMobile/7”))
{
result = new ViewEngineResult(new WebFormView(
“~/Views/MobileIE7/Index.aspx”, string.Empty), this);
}
if (result == null || result.View == null)
{
result = base.FindView(controllerContext, viewName,
masterName, useCache);
}
return result;
}
public bool UserAgentIs(ControllerContext controllerContext,
string userAgentToTest)
{
return controllerContext.HttpContext.Request
.UserAgent.IndexOf(userAgentToTest,
StringComparison.OrdinalIgnoreCase) > 0;
}
}
}

The FindView method checks the user agent to determine the browser type, and then it returns an appropriate ViewEngineResult instance.

For more information about creating websites for mobile devices, see the post, “Mix: Mobile Web Sites with ASP.NET MVC and the Mobile Browser Definition File,” on the blog, Scott Hanselman’s ComputerZen.com (http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx).

 


Posted

in

by

Tags: