• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Nice way of detecting modern mobile browsers in .NET?

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Nice way of detecting modern mobile browsers in .NET?

    For my latest Plan C i need to hide a couple of spans from mobile browsers as they dont lend themselves well to low res display.

    The inbuilt mobile browser detection in .NET doesnt work with modern stuff such as the iPhone so has anyone got a decent function they use to detect these? Maybe some sort of inStr as shown in http://www.codeproject.com/KB/aspnet/mobiledetect.aspx - but that particular list looks too big and a candidate for misidentification? Only interested in the main ones like iPhone/Blackberry but dont know what others are popular.

    Or is it just easier to detect screen res and act according to that instead?

    Ta

    #2
    Like me you've found that a lot of browsers (and not just mobile ones) are not recognized by the default browser files that ship with .NET & Visual Studio. I encoutered this problem a while back where Chrome was not recognized at all and for my application I wanted the users browser out of the request for logging purposes. I hoped I could use the Request.Browser.Browser but found in many cases it would hold an empty string if the user was using an unrecognised browser.

    At first I started down the route of looking at the HTTP_USER_AGENT like your CodeProject link, but then learnt a better way; you can create your own browser definition files and place them in the App_Browsers directory of your web app. This makes ASP.NET more intelligent to new browsers and also correctly populate the Request.Browser.Browser.

    If this seems like a lot of work, or if you have no inclination learning how a .browser file needs to be structured, use the .browser files that this guy maintains in his browser identification project: http://owenbrady.net/. They always seem to be fairly up to date and I see they do now include both the iPhone and Blackberry platforms.

    Once all that's working, it would be fairly trivial to write your own little extension method for the Request.Browser class based on this e.g. bool isMobileBrowser()

    HTH
    Moving to Montana soon, gonna be a dental floss tycoon

    Comment


      #3
      Excellent, thanks. Have messed around with the .browser files before when fixing things like Safari's duff handling (well .NET's inability to recognise its capabilities) of the ASP:menu control but had not thought of using them in this context.

      Ta.

      Comment

      Working...
      X