ASP.NET AJAX and Windows Mobile - More on Browser Identification

You Can Take it With You

Syndication

News

  • Don't miss the next Windows Mobile Webcast... Unit Testing for Mobile Devices: http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032382824&EventCategory=4&culture=en-US&CountryCode=US.

Ya know, ASP.NET AJAX (Atlas) and Windows Mobile just seems to be the challenge that just keeps on giving. J

As I talked about yesterday, we now know how to get Atlas and Windows Mobile to work together. The next challenge is to be sure that Atlas correctly recognizes all of the capabilities of IE Mobile. As I mentioned last week, there are two workarounds for the fact that Atlas doesn't recognize IE Mobile.

The first is to set the ClientTarget to 'ie5' in the ASPX pages <%@ Page %> directive. This correctly enables the Atlas features but it causes the page to treat all clients (including desktop clients like IE 7) as if they are IE 5.

The other workaround (arguably this is more a solution than workaround) is to define a *.browser file that properly describes the IE Mobile capabilities. Based on the information provided at this years MEDC, it appeared that the only additional capabilities that the *.browser file needs to define is support for W3CDomVersion 1.0. My observations indicate that this isn't quite accurate. I'm finding that Atlas behaves much better on IE Mobile when the client target is set to 'ie5' than it does when using such a simple *.browser file.

To get Atlas to fully enable everything that IE Mobile supports, I need to workout everything that needs to be in the *.browser file which may take me a little time. In the meantime I've found a reasonable short-term workaround.

Rather than set the ClientTarget directly in the ASPX page which affects all clients. You can add code to check the UserAgent value and set the ClientTarget only when the client is IE Mobile. The key is to let the incoming request progress far enough so that the Request object is instantiated but to set the ClientTarget value early enough so that all the code that depends on the browser capabilities will believe that the client is IE5.

With all this in mind, the right place to set the ClientTarget is to override the Page class' FrameworkInitialize method which is exactly where the ASP.NET framework sets the value when the ClientTarget is set in the <%@ Page %> directive.

public partial class _Default : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    // Do Page Load Stuff
  }
  protected override void FrameworkInitialize()
  {
    base.FrameworkInitialize();
    if (Request.UserAgent.IndexOf("IEMobile") > -1)
      ClientTarget = "ie5";
  }
}

This isn't my preferred long-term solution but it works for now.

As soon as I figure out everything that needs to be in the *.browser file to get the same results, I'll post that information.


Posted Sep 25 2007, 09:58 AM by jim-wilson

Comments

Richard Jones wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 09-26-2007 12:06 PM
http://www.binaryrefinery.com/main/PermaLink,guid,9bc4bf0b-9578-489a-b608-074c9bf0d2c4.aspx
Jim Wilson wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 09-26-2007 1:32 PM
Richard;

Thanks for the pointer - I just need to take things a bit further.

The solution you reference takes care of redirecting to a mobile-specific page when the request comes from a mobile device. What I'm trying to resolve is how to get all of the HttpBrowserCapabilities values set appropriatly for IE Mobile 6.12 feature support.

Given the VS2005 and VS2008 Beta2 browser definitions, Request.Browser significantly under reports the IE Mobile 6.12 supported feature set even when directed to a mobile-specific page. As a result, a number of ASP.NET features that IE Mobile 6.12 is capable of supporting are not used, resulting in the page that is sent to the WM6 device not being as content/behavior rich as it can be.

Thanks,
- Jim
Rob Tiffany wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 10-09-2007 4:32 PM
This is great stuff Jim! The community thanks you for all this hard work in figuring out the mysteries of Ajax on IE Mobile. I guess we need to spend more time doing articles, how-to's, and webcasts on the mobile web.
Jim Wilson wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 10-10-2007 5:53 AM
Rob;

Thanks - I really appreciate your kind words.

I totally agree on the content issue. We have last month's IE Mobile AJAX webcast still available so that's a start. I've got a couple of short how-to papers in mind plus one larger paper that provides the more detailed overall story.

We can sync up on the details of the plans off-line.

For those who missed it, last month's IE Mobile AJAX webcast is still available at http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032348421&Culture=en-US

Thanks again,
Jim
ttklf4 wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 10-20-2007 11:17 PM
Your blog post is just as well misleading as the PowerPoint slides which one can download in MelSam's Blog (http://blogs.msdn.com/melsam/archive/2007/06/18/techmela-2007-thank-you-and-presentations.aspx).

If you use the ClientTarget attribute and set its value to "ie5" or "uplevel" you disable the ASP.NET browser detection with the HttpBrowserCapabilities and the server will send the necessary AJAX scripts to the client. This has nothing to do with the functionality of ASP.NET AJAX in the client browser.

Because ASP.NET AJAX uses the client capabilities which are defined in HttpBrowserCapabilities to determine if partial-page rendering, i. e. Ajax calls, is supported one should use a .browser file to configure IEMobile on the server.

And one additionally clarification:

"Atlas" was the name of the Microsoft ASP.NET Ajax framework in the beta phase. Since the RTM it is called ASP.NET AJAX and "Atlas" is no more used.
Jim Wilson wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 10-21-2007 10:31 AM
ttklf4;

I always welcome disagreement and debate. In this case though, it appears that you didn’t actually read this post before commenting on it. Your points about using ClientTarget=’ie5’ and HttpBrowserCapabilities simply repeat the same concerns I note above.

Let me clarify….

To use only HttpBrowserCapabilites to determine browser feature support requires that we have a *.browser definition that fully and accurately identifies IE Mobile’s features. Note in the 3rd full paragraph above (starts “The other workaround…”) specifically says that the preferred solution is to use a *.browser file … but … no one has publicly identified the appropriate settings for that *.browser file. If you have done so, please share as it’s something many of us could use.

Your point about setting the ClientTarget circumventing the HttpBrowserCapabilites settings… That issue is the core point of the above blog post. That’s the reason that the post provides code to show how to avoid that problem by setting the ClientTarget to ‘ie5’ programmatically so that you can check the UserAgent value and set the ClientTarget only when the client is IE Mobile. Using this code, all non-IE Mobile browsers will use the regular HttpBrowserCapabilities just as they always do. Again, we could eliminate this issue if someone can invest the time to identify the appropriate *.browser settings for IE Mobile.

Regarding the use of the codename Atlas… I and I’d imagine most of the readers are fully aware that Atlas refers to ASP.NET AJAX version 1.0 prior to the product’s RTM. The full product name for ASP.NET AJAX or more accurately ASP.NET AJAX version 1.0 (versus version 3.5 which ships with Visual Studio 2008) is a bit long to fully type in a forum as informal as a blog. So I could make up my own abbreviation which I would then correlate to the full term parenthetically … or I can use a well known alias such as Atlas (which I also correlate parenthetically). It’s not like I’m the first to use a product’s pre-RTM codename as an abbreviation.

I do need to address something in your reply that I find misleading. You state that the use of ClientTarget to affect the HttpBrowserCapabilities "… has nothing to do with the functionality of ASP.NET AJAX in the client browser”. That’s simply not true. If one does not provide the appropriate settings on the server (such as when using ClientTarget=’ie5’), ASP.NET AJAX will not generate the content necessary to wire-up partial page updates on the client. Give it a try … you’ll find that without the server believing that the client has adequate feature support (the default case for IE Mobile), the page sent to the client will *always* do full page updates.

-Jim
Jim Wilson wrote re: ASP.NET AJAX and Windows Mobile - More on Browser Identification
on 11-02-2007 7:05 AM
A quick follow up to this post...

It is no longer necessary to use the technique I describe in this post. The *.browser file contents required for ASP.NET to properly recognize IE Mobile devices is available at http://www.pluralsight.com/blogs/jimw/archive/2007/10/23/48836.aspx

Jim

Add a Comment

(required)  
(optional)
(required)  
Remember Me?