This code is not intended for browser detection and is not for device capability either.
For operation with a smartphone, find out what the smartphone puts in the UserAgent property then change the word "smartphone" in the code below accordingly. Plus, change the index number at "device(0)" to "device(1)" or as per your needs.
Why is this code in "global.asax"?
We want to get ASPNET to do something other than what it automatically does when it gets a request to send out an ASP.NET Web page. In this case "default.aspx" has been called. If the page that is being used for device detection is named differently, just replace
"default" with the name of your Web page:
We want ASPNET to send out the right ASP.NET Web page per the device being used. We do not want ASPNET to go straight into processing "default.aspx" as a Pocket PC device is calling it. If there was no code in the event handler below, ASPNET would just dish
out "default.aspx", desktop version, to any device calling it.
Enjoy.
Sub Application_BeginRequest(ByVal sender
As Object,
ByVal e As EventArgs)
' Fires at the beginning of each request
' A device detection procedure.
' Is the “default.aspx” Web page calling?
Dim page
As Integer
page = Request.CurrentExecutionFilePath.IndexOf("default")
' If so, run this code.
' page is "-1" if the calling Web page is not "default.aspx"
' page is "0" or greater if it is.
If (page > -1)
Then
Dim hostname
As String
Dim result
As Integer
Dim device()
As String = {"PPC", "Smartphone"}
' Get the device details.
' In the string returned by UserAgent will be the name of the device type
hostname = Request.UserAgent
result = hostname.IndexOf(device(0)) ' Test for "PPC"
If (result = -1)
Then
Exit Sub ' Go on and send out the desktop version of "default.aspx"
Else
Response.Redirect("/PDA/default.aspx") ' send out the Pocket PC version.
' The address above (/PDA/default.aspx)
may be different for your situation.
Member
10 Points
309 Posts
How to direct ASP.NET to Web page for a Desktop or Pocket PC
Jan 24, 2006 09:06 AM|bluekiwi|LINK
For operation with a smartphone, find out what the smartphone puts in the UserAgent property then change the word "smartphone" in the code below accordingly. Plus, change the index number at "device(0)" to "device(1)" or as per your needs.
Why is this code in "global.asax"?
We want to get ASPNET to do something other than what it automatically does when it gets a request to send out an ASP.NET Web page. In this case "default.aspx" has been called. If the page that is being used for device detection is named differently, just replace "default" with the name of your Web page:
before:
page = Request.CurrentExecutionFilePath.IndexOf("default")
after:
page = Request.CurrentExecutionFilePath.IndexOf("detect")
We want ASPNET to send out the right ASP.NET Web page per the device being used. We do not want ASPNET to go straight into processing "default.aspx" as a Pocket PC device is calling it. If there was no code in the event handler below, ASPNET would just dish out "default.aspx", desktop version, to any device calling it.
Enjoy.
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
' A device detection procedure.
' Is the “default.aspx” Web page calling?
Dim page As Integer
page = Request.CurrentExecutionFilePath.IndexOf("default")
' If so, run this code.
' page is "-1" if the calling Web page is not "default.aspx"
' page is "0" or greater if it is.
If (page > -1) Then
Dim hostname As String
Dim result As Integer
Dim device() As String = {"PPC", "Smartphone"}
' Get the device details.
' In the string returned by UserAgent will be the name of the device type
hostname = Request.UserAgent
result = hostname.IndexOf(device(0)) ' Test for "PPC"
If (result = -1) Then
Exit Sub ' Go on and send out the desktop version of "default.aspx"
Else
Response.Redirect("/PDA/default.aspx") ' send out the Pocket PC version.
' The address above (/PDA/default.aspx) may be different for your situation.
End If
End If
End Sub