Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.net Redirect to Mobile(Blackberry) version page

Status
Not open for further replies.

berkshirea

Technical User
Mar 22, 2009
97
GB

Hi guys, I am experimenting with a mobile version (for blackberry) of a site and would like the users to be redirected to this mobile site version. I used the simulator and a real blackberry but it's not redirecting.

I tested it for browser capabilities using the simulator and the real blackberry and gives the same info:

Browser type: Unknown
Browser version: 0.0
Major version: 0
Platform: Unknown
.
.
.



Below is the code for redirect:

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

If Request.Browser("IsMobileDevice") = "true" Or Request.Browser("Blackberry") = "true" Then

Response.Redirect("blackberry.aspx")
Else
Response.Redirect("desktop.aspx")
End If
End Sub


Thanks for any help.
 
try
Code:
If Request.Browser("IsMobileDevice") = True.ToString() Or Request.Browser("Blackberry") = True.ToString() Then
   Response.Redirect("blackberry.aspx")
Else
   Response.Redirect("desktop.aspx")
End If
that might be one reason.

However this logic is very intrusive. you would need to place it on every single page. I recommend using Master pages and Themes to style the webform. This way you keep 1 webform and simply alter the Theme/Master for display purposes.

either that or create your own HttpModule to redirect the user to the proper place (computer vs. mobile device)

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
try changing this:
Code:
Request.Browser("IsMobileDevice") = "true"
to this
Code:
Request.Browser("IsMobileDevice") = true 
OR
Request.Browser("IsMobileDevice")
 
Hi jmeckley i did your suggestion but still redirects to the desktop.aspx.


Hi jbenson001 i did your your suggestion but it says:
[FormatException: Input string was not in a correct format.].....
[InvalidCastException: Cast from string "" to type 'Boolean' is not valid.]

any other ideas guys?

 
Sorry, I made a mistake in my post. Here is the exact code we use on our site that works perfectly:
Code:
If Request.Browser.IsMobileDevice OrElse _
                Request.Browser("BlackBerry") = "true"
...
...
EndIf
 
Guys, thanks very much for your help.

I have found out that my server's browsercap in machine.config is out of date. I just updated it and now it seems to work.

Have a nice day.

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top