Click here to Skip to main content
Click here to Skip to main content

Configuring .Net 2.0 to recognise the BlackBerry browser

By , 24 Jul 2006
 

Introduction

While writing ASP.NET applications targeting the BlackBerry browser I have made some interesting discoveries. In this article I will show how to configure .NET 2.0 to recognise the BlackBerry browser so that it behaves as you would expect.

Background

I have developed several ASP.NET 1.1 applications targeting the BlackBerry browser version 4.1 on the 7290 device and more recently the 8700g. I have been upgrading those projects to ASP.NET 2.0 and was quite baffled initially, when several features would just not work.

Creating a BlackBerry.browser config file

After a quick look through the \WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers directory I discovered that version 2.0 of the framework does not ship with configuration details for the BlackBerry browser. Some of the older browsers are covered with the goAmerica.browser configuration file but that doesn't cover the newer browsers.

To find out what the framework knows about a browser you can create a page which writes out some details:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("<B>User Agent:</B> " + Request.UserAgent + "<BR />");
    Response.Write("<B>IsMobileDevice:</B> " + Request.Browser.IsMobileDevice
    + "<BR />");
    Response.Write("<B>Browser:</B> " + Request.Browser.Browser + "<BR />");
    Response.Write("<B>Version:</B> " + Request.Browser.Version + "<BR />");
    Response.Write("<B>Major:</B> " + Request.Browser.MajorVersion + "<BR />");
    Response.Write("<B>Minor:</B> " + Request.Browser.MinorVersion + "<BR />");
}

Browsing to this page on a Blackberry the UserAgent will return something like this:
   BlackBerry8700/4.1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/-1
This is useful information but Browser name and version information are not returned.

Creating a Blackberry.browser config file is pretty straight forward. Having a read through the other *.browser files will give you an idea of what properties can be set. Here is the configuration which I have created:

<browsers>

  <browser id="BlackBerry" parentID="Default">
    <identification>
      <userAgent match="BlackBerry(?'model'\d+)/(?'version'((?'major'\d+).
(?'minor'\d+).(?'other'\d+)))" />
    </identification>

    <capabilities>
      <capability name="browser"             value="BlackBerry" />
      <capability name="isMobileDevice"      value="true" />
      <capability name="javascript"          value="true" />
      <capability name="ecmascriptversion"   value="1.3" />          
      <capability name="version"             value="${version}" />
      <capability name="majorVersion"        value="${major}" />
      <capability name="minorVersion"        value="${minor}" />
      <capability name="supportsCss"         value="true" />
      <capability name="frames"              value="false" />
      <capability name="cookies"             value="true" />
    </capabilities>
  </browser>
  
</browsers>

In the browser tag we just set the id and parentID attributes. In the identification tag we create a regular expression to capture a match on the userAgent we looked at earlier. Under capabilities we set the various properties for the browser.

One of the most important capabilities here is the ecmascriptversion. It lets the framework know that its ok to write out the __doPostBack javascript method and the __EVENTTARGET & __EVENTARGUMENT hidden fields. These are used by events such as the SelectedIndexChanged on a DropDownList control.

There are many other properties which can be set but I have found these sufficient for my needs. Enter these details in a text file and save as BlackBerry.browser in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Browsers directory.

ASP.NET Browser Registration Tool

Creating the file is only half the job. We now need to let the framework know about it. There is a command line tool called aspnet_regbrowsers.exe which creates an assembly based on the information in the *.browser files and installs the assembly in the global assemly cache.

From a command prompt enter the path to aspnet_regbrowsers.exe and use the -i switch to register the browser configurations. For my installation the path is as follows:
   C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regbrowsers.exe -i
Just check that this is the correct location for your installation.

More information on aspnet_regbrowsers.exe can be found here.

Conclusion

The ecmascriptversion can be an important property for the framework to know about a browser. The applications I have upgraded from ASP.NET 1.1 to 2.0 now behave as they should on the BlackBerry browser.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Declan Bright
Architect
Ireland Ireland
Member
I have been designing and developing business solutions for the aviation and telecommunications industries since 1999. My experience covers a wide range of technologies and I have delivered a variety of web and mobile based solutions.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberhezhicheng8 Mar '11 - 8:19 
Converted it to the format needed for the Web.config file and it worked like a charm. Thanks!
Generalecmascriptversion shows 1.4 but __EventArgument and __EventTarget still don't rendermemberdubloons13 Dec '10 - 7:31 
Hello - this is a wonderful article, but I still seem to be having some issues with blackberry devices. When I hit the site from a regular browser I see the following <form name="aspnetForm" method="post" action="showProduct.aspx?SEName=dell-xps-630&ProductID=49"...
GeneralSupport for different Blackberry modelsmembermuppet00711 Mar '10 - 23:51 
Hi Declan,   We recently had to add support for different Blackberry models, and since the screen sizes are different we decided to feed them different stylesheets. You already have a regex match for the model, so I've just added it to the capabilities in order to use it programmatically...
GeneralMobile Device Browser File from Codeplex - over 400 devices (including Blackberries)memberneilio2 Aug '09 - 15:52 
This approach looks really promising - then I came across this the Mobile Device Browser File. Apparently it has detailed capabilities for over 400 mobile devices and is freely downloadable from CodePlex. Several blog entries I read about it suggest the file was compiled from Microsoft's...
GeneralIf this isn't working for you - make sure to check the line breaks in your BlackBerry.browser file.memberJesse Fatherree6 Jul '09 - 10:57 
I did exactly as the article stated and it wasn't working at all.   If you create a file called browser.aspx and post the page load code from the article, it should show up on the BlackBerry with the browser listed correctly. Mine kept saying unknown until I went back to the...
General3.5 Support [modified]memberMobby Imam24 Feb '09 - 9:21 
I had tried everything in this tutorial, but all my efforts ended up in vain. Finally, after a two day respite, I downloaded a simulator for VS 2008(http://na.blackberry.com/eng/developers/browserdev/devtoolsdownloads.jsp)[^] and started playing around with the functionalities. Everything worked...
GeneralRe: 3.5 Supportmembermuppet00711 Mar '10 - 23:47 
This is exactly the same as Declan's .browser file, except RIM added the useless generic xmlns.
GeneralQuestion that might be specific to my BlackBerrymemberzuurg18 Dec '08 - 11:45 
First of all, great article!   I created the sample page that you referred to at the beginning of your article to see what values would come back, and I was wondering if what was returned would need to be factored into the writing of the .browser file.   Here's what came back:...
GeneralVB page load codememberbdempster4 Aug '08 - 9:52 
Created using Visual Web Developer 2008 I had to add the ".tostring" to get it to work. ------------------------------------------------   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load   Response.Write("<B>User...
GeneralYou can add the BlackBerry.browser file to your projectmemberRohinton Collins29 Apr '08 - 13:32 
You can also just add browser definition files to your projects on a project-by-project basis.   I just tried to add an XML file to my web project, gave it a .browser extension and Visual Studio advised me to put it in the App_Browsers folder, which it created.   Publish your...
GeneralRe: You can add the BlackBerry.browser file to your projectmemberDeclan Bright30 Apr '08 - 9:40 
Hi Rohinton,   I didn't know it was possible to add a browser file this way. It certainly makes it easier although registering the file with the ASP.NET Browser Registration Tool may give better performance as the settings are compiled and installed in the GAC.   Thanks for the...
GeneralThank you!memberNetNat9 Mar '08 - 3:15 
Just what I needed. Works perfectly with my 8310 Curve.
GeneralRe: Thank you!memberDeclan Bright16 Mar '08 - 7:39 
You are welcome   Declan Bright www.declanbright.com
Questionpostback still failing, any ideas?memberdB.29 Oct '07 - 17:39 
With the browsers file I don't get a JavaScript error any more, but I don't get the postback to fire either. The browser just hangs. Any ideas?   Try http://mobile.foodcandy.com, click on "Foodies" and try to navigate between pages.   Appreciated.   dB. - dblock.org
AnswerRe: postback still failing, any ideas?memberDeclan Bright29 Oct '07 - 23:24 
Hi dB   I can only speak for my 8700 but your site is working fine on it. Hopefully that means you got the problem sorted out. The site looks good but you should consider disabling viewstate, it will halve the response times on most of your pages.   Declan Bright...
GeneralRe: postback still failing, any ideas?memberdB.30 Oct '07 - 12:15 
Seems to work with several blackberries my friends have here, but not with the simulator! Hmmm...   dB. - dblock.org
Questioni want send message to blackberry from windows desktop applicationmembersriram30308 Aug '07 - 19:14 
i want send message to blackberry from windows desktop application ple provide sample application   thanks
AnswerRe: i want send message to blackberry from windows desktop applicationmemberDeclan Bright8 Aug '07 - 21:24 
Hi sriram3030   It depends on what you mean by "message". You could just send an email message to a Blackberry. If you want to push HTML content to a device then this article may be useful: A Simple C# Push Application[^]   Hope this helps   Declan Bright...
GeneralA slight change neededmemberzewar962 Aug '07 - 7:51 
The RegEx that is being used does not work for all BlackBerrys. The Verizon 8703e identifies itself as an 8703e.*.*.* so the RegEx won't pick it up. To save yourself a horrible headache in trying to find out why you are getting Javascript errors, change the RegEx to:   This should...
GeneralRe: A slight change neededmemberDeclan Bright2 Aug '07 - 21:51 
Hi zewar96   Thanks for posting your findings, I'm sure this will save people a lot of trouble.<useragent match="BlackBerry((?'model'\d+\w?)/(?'version'((?'major'\d+).(?'minor'\d+).(?'extra'\d+))))"> ( Note: To display the xml element in the message you need to replace any "  ...
GeneralRe: A slight change neededmemberBrendanM72114 Aug '07 - 6:01 
This worked phenomenally, thank you for your help.   There is a slight syntax problem with that line though. It should be...     The A in Agent wasn't capitalized and the ending tag wasn't closed. This made ASP throw an exception.
GeneralRe: A slight change neededmemberharsha.809 Sep '09 - 3:01 
You saved my life!   We had a production server issue where PostBacks on BlackBerry was failing when we updated the .Net framework to 3.5! It was working before on 2.0 framework with a BlackBerry browser definition file.   I followed exactly the steps you mentioned and updated the...
GeneralStill Not Workingmembergialo24 Jul '07 - 14:23 
Hi,   I did everything that the article specified, and still my blackberry is not properly posting back.   I am receiving a Javascript Error.   Any additional thoughts?   Mark Gialo
GeneralRe: Still Not WorkingmemberDeclan Bright24 Jul '07 - 21:22 
Hi Mark   What is the javascript error? Are you getting the javascript error for every postback or just from certain controls? Is this an application which was originally built for a desktop browser or is it a new development targeting mobile browsers? The Blackberry browser does not...
GeneralBlackberry ASP SQL Data Problemmembernwack-nwack21 May '07 - 11:02 
I have developed a small ASP.NET 2.0 page that retrieves data from a SQL Server. I have kerberos delegation set up because the webserver is different then the SQL Server. The page works fine from an IE browser on a desktop. When I run the page from a Blackberry sometimes it rtns data but most of...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 24 Jul 2006
Article Copyright 2006 by Declan Bright
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid