Determining what capabilities ASP.NET is using to render pages

When you make a request to an ASP.NET based site, the browser's capabilities are determined by the <browserCaps> section in the 1.x Framework and the .browser files in the 2.0 framework.  Knowing which capabilites that ASP.NET is using to render the page can be especially important in mobile applications. 

You can use the following page to return all the MobileCapabilities for the device by browsing the page:

<%@ Page language="c#" AutoEventWireup="true" Inherits="System.Web.UI.MobileControls.MobilePage" %>
@ Import namespace="System.Web.Mobile" %>
@ Import namespace="System.Reflection" %>
<script runat="server">
protected void Page_Load(Object sender, EventArgs e)
MobileCapabilities capabilities = (MobileCapabilities)Request.Browser;
          Type t = typeof(MobileCapabilities);
          PropertyInfo[] propertyInfos = t.GetProperties();
          foreach(PropertyInfo pi in propertyInfos)
Label lbl = new 
                    lbl.Text = pi.Name +
" = " + capabilities[pi.Name];
<mobile:Form id=Form1 runat="server">

The MobileCapabilities are determined by the UserAgent string that ASP.NET receives.  You can log the UserAgent string in the IIS logs or you can use a tool like Fiddler or Web Development Helper in IE to get this information.  Once you have the UserAgent string, you can use Fiddler to pass the same UserAgent string while browsing in IE.  This will give you a larger viewing area for looking at hte list of MobileCapabilities.

Comments (2)
  1. aarontallen says:

    A problem we are facing is that as new phones/devices are produced ASP.Net 2.0 doesn’t recognize them for the capabilities they have (JavaScript, Table Support, etc.).  

    Do you have any recommendations on how to stay on top of new devices?  Supposedly Microsoft won’t be releasing device updates like they used to in 1.1.  If they couldn’t stay on top of all new devices, how am I supposed to?

    The unfortunate effect is that someone with a snazzy new device, with more then the necessary caps get’s the watered down no javascript basic version when they should be getting the site in all its glory.

    Thanks in advance for any insight/help you have.  Thank you also for this blog, I’ve added it to my list of places to go for solutions.


  2. Jerry_Orman says:

    Right, there won’t be a device update as there was in 1.1.  The following link talks about the .browser files and capabilities.

    The accurate way would be to profile the device, though that would be tricky with an internet based app where you have no idea what devices users are browsing with.  However, you could go the route of forcing browsers with a common user agent string to have uplevel capabilities.  The downside of this approach is the potential for downlevel devices to get content they can’t render.

Comments are closed.

Skip to main content