Category Archives: Software

Detecting mobile browser in ASP.Net

Detecting mobile browsers can be a bit of pain.  Whilst it is relatively easy to get browser information through the User Agent string, it is not such a simple task to identify the client device type.  There is no defined property within the user agent field that says I’m a mobile device.  User Agent values differ widely between devices and browsers, so it is necessary to use some less than elegant detection code.

I recently added this detection functionality to the Camino CMS Framework, and Calzada’s preferred method is using regular expressions.  After some playing, we came up with the following regex:

(?i)(android(?:.+mobile)|applewebkit.+(?:\(KHTML, like Gecko){1}|avantgo|blackberry|blazer|docomo|elaine|fennec|htc|kindle|lge|linux.+armv|mmp|mms(?:.+midp){1}|mobile|mot(?:.+midp){1}|nintendo.+(?:3ds|wii)|nokia|nook|opera(?:.+mini|.+mobi){1}|palm|polaris|phone|ppc|psp|samsung|sec|sony|symbian|tablet|up\.browser|vodafone|wap|webos|windows(?:.+ce|.+mobile){1}|xda|xiino

A simplified ASP.Net detection code would look something like this:

Function IsMobileBrowser() As Boolean
Dim regex As New Text.RegularExpressions.Regex("(?i)(android(?:.+mobile)|applewebkit.+(?:\(KHTML, like Gecko){1}|" & _
"avantgo|blackberry|blazer|docomo|elaine|fennec|htc|kindle|lge|linux.+armv|mmp|mms(?:.+midp){1}|mobile|mot(?:.+midp){1}|" & _
"nintendo.+(?:3ds|wii)|nokia|nook|opera(?:.+mini|.+mobi){1}|palm|polaris|phone|ppc|psp|samsung|sec|sony|symbian|tablet|" & _
"up\.browser|vodafone|wap|webos|windows(?:.+ce|.+mobile){1}|xda|xiino", Text.RegularExpressions.RegexOptions.IgnoreCase)
Return regex.IsMatch(HttpContext.Current.Request.ServerVariables("http_user_agent").ToString)
End Function

There are a couple of key points to bear in mind with this method:

  1. It is not perfect.  No matter how you tailor and tweak the regular expression, you are inevitably going to get some false positives and false negatives.
  2. This is not a write and forget function.  As the number of mobile devices and manufacturers proliferate, the accuracy of the regular expression will diminish.  To compensate, it is necessary to regularly review, test and update where required.  To ensure that this is done, this process has been added this to the Camino development lifecycle.
  3. Not all mobiles or mobile users may wish to use mobile variant of a website.  Do bear in mind that some tablets have a sufficiently large screen to view the normal version of a website.
I am aware that this is not an elegant nor wholly accurate solution, and there are plenty of programmers out there that will view it as a kludge, but in many ways it is a product of its’ ingredients.  Until such time when all browsers will provide a property that simply states I’m running on a mobile device, then this will have to do.

.Net Campaign to kill IE6

I came upon this little gem when I was trawling around for something completely unrelated – as you do.  .Net magazine has instigated an online campaign to kill Internet Explorer 6.

I’m always a little wary of online campaigns.  Perhaps I’m overly paranoid, but I am inheritently suspicious of any campaign or venture that claims to be beneficial that looks a little too slick and well organised for its’ own good.  The campaign website is a custom product with slick, targeted design and content.  Then again, you would expect any website directly associated with .net to incorporate a high design element.

I approach IE6 with two different perspectives, and unusually, they nearly cancel each other out.

From my web developer’s perspective, IE6 has always been a complete pain.  Its’ complete indifference to standards and the arbritrary way in which it renders HTML/CSS has infuriated and caused significant impact on development schedules.  From a purely web perspective and with the benefit of hindsight, IE6 significantly stagnated web development.

From the other perspective, that of the IT Support Guy, it is simply not practical to simply kill off IE6.  Firstly, there is still a substantial user base out there.  Significant number of businesses still run Windows 2000 on a high proportion of their computers, and their IT departments are unlikely to wish to migrate across to a non-Microsoft browser.  This is certainly true at the SME end of the market where computers tend not to be replaced as part of a defined replacement program, but as and when a computer fails beyond economic repair.

Is Microsoft likely to release a version of IE7 for Windows 2000?  Not likely.  In the eyes of Microsoft, Windows 2000 is a dead operating system.  It has been superseded not once, but twice.  The only option here is to upgrade or replace any Windows 2000 PC.  Not a practical or viable option in the SME arena; a computer works until it drops dead.

One suggestion has been that Windows 2000 users simply migrate to another browser like Mozilla Firefox or Opera.  For the casual home user, this is eminently doable, but for business users, things are not so clear cut.

There are some applications that require Internet Explorer to work, or utilise within one of their own components.  I know of one Oracle/Java web application that would only work properly in Internet Explorer – kind of curious since it was Java based.  There is a high market penetration of web-based applications that exploit the integrated security model within Internet Explorer, Sharepoint being an ideal example of one.

IE6 is also remotely and centrally manageable via Group Policies.  In any corporate network, this is a valuable management function and something that it still not available in IE’s competitors.  Its’ updates may also be centrally managed (WSUS) and monitored.  IE, whatever its’ incarnation and foibles, is an enterprise-level web browser.

Internet Explorer has also moved on.  We are now at version 8, which is a marked improvement over IE7 and an almost quantum leap up from IE6.  Sadly though for all its’ improvements IE8 maintains the Microsoft tradition of its own unique interpretation of W3C standards.

I am no fan of IE6, and in most circumstances I would like to see it gone but the pragmatist says this is wishful thinking.  This campaign, whilst with an admirable intent, will not get rid of it no matter who is involved or how many.  There are simply too many economic and operational constraints involved.  IE6 will only be dead and forgotten when Windows 2000 is, and given its’ longevity that may be for some time yet.

Internet Explorer 8

Internet Exploder Explorer 8 has finally arrived, and unlike the Beta version, it hasn’t crashed my computer.  Yet.

Even 5 years ago, the arrival of a new browser was a big event.  Nowadays, with the presence of Firefox, Safari and Chrome, its’ release is a little bit of an anticlimax.  One hopes that that IE8 will be the browser equivalent of Windows 7: good software as it should have been in the first place.  I’ve had too many “interesting” experiences with IE7 over the last couple of years.

So why, the fuss.  Well, I’m not going to repeat or perform an in-depth review of IE8.  There are plenty of other websites out there doing that and I simply haven’t spent that much time with it yet.  I’m looking forward to IE8 as it finally promises a browser from Microsoft that it is in some way consistent and compliant with various web standards.  As many web designers/developers out there will tell you, the CSS rendering in previous versions of IE7 is either fundamentally broken, wrong or just plain inconsistent.  I have spent far too much time making websites IE friendly with the resultant CSS stylesheets being a discordant mess.

This is not to say that IE is the the only perpetrator out there.  My favoured browser, Mozilla Firefox, still doesn’t pass the ACID3 test.  Neither does Google Chrome. I haven’t tested in Safari as my patience with Apple software evaporated many moons ago.  I can honestly say that I haven’t use Opera in many years.

Consistency has actually improved over the past decade though.  I can remember back to 2000/1 when the standard practice at the company I was then working for was to develop separate stylesheets for each browser.  Each website would programmatically detect the user’s browser and return the corresponding stylesheet.  Thankfully, things have moved on.  Back then, we only realistically worried about Internet Explorer and Netscape Navigator (remember that?).  Now we have a diverse range of browsers, and importantly, host operating systems and hardware platforms.

So, back to Internet Explorer 8.  I will continue to play with it over the next couple of weeks, and I will post an update with my various comments and opinions in the near future.  Will it ever replace Firefox?  No.  I am currently well and truly sold on the sheer extensibility of Firefox.  I would be completely lost without extensions like PDF Download and Download StatusBar.  If I’m honest, usage of IE8 will probably be restricted to Windows Update and the occasional download from Microsoft that requires a Windows Genuine Authentication check.

Toolkit: Virtual CloneDrive

As someone who uses ISO files on an almost daily basis, a tool like SlySoft Virtual CloneDrive is a brilliant utility that allows the easy mounting of any ISO file as local disk drive.  I’ve used several similar utilities over the years, but this one is the best I’ve used yet.  It has been installed on a variety of PCs including my venerable Thinkpad, and I have yet to experience any problems.

Virtual CloneDrive is a free download available through the SlySoft website at http://www.slysoft.com/en/virtual-clonedrive.html.

As usual, you use Virtual CloneDrive at entirely your own risk.