Wednesday, August 02, 2006

Detecting Mobile Browsers

As discussed in our last meeting, web applications can be built to handle both PC browsers and mobile browsers. To do so, the application needs to detect if the browser is a mobile device and redirect the application to a page designed to display UI adequate for the smaller mobile browser. Detecting the browser is done using the following code sample, and it's typically placed in the Page_Load() of the login.aspx or default.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
If Request.Browser.IsMobileDevice = True Then
End If
End If

Catch ex As Exception
End Try

End Sub


Mark Harr said...

I want to know what your ProcessEx() does. said...

ProcessEx() is used as a central location for logging all Exceptions. In this particular instance, I simply write the error to a log file and then display the error to the user using a specific .ASPX page. Listed below is the code used for this scenario.

Public Shared Sub ProcessEx(ByVal Ex As Exception)

Dim strMsg As String
strMsg = " Error=" & Ex.Message & ControlChars.CrLf
strMsg &= " Method=" & System.Reflection.MethodInfo.GetCurrentMethod.Name & ControlChars.CrLf
strMsg &= " Stack Trace=" & Ex.StackTrace & ControlChars.CrLf

Dim cls As New clsOpMgmt

End Sub

Mark Harr said...

Thanks. Now what does clsOpMgmt do? said...

clsOpMgmt is a class composed of functions used for handling errors. Some of the methods include WriteEntry() which writes to a log file, SendEmail() used for sending automated emails when certain erros occur, and ShowError() which is used to display an error or exception in a user friendly manner.

zaption said...

You could also use a service like