Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons why ASP.NET AJAX would be disabled

I have an ASP.NET application that uses ASP.NET AJAX and the AJAX Control Toolkit. The application runs fine on all recent browsers on a PC. It also works fine on my iPad, at least the first time the application is accessed. I have found that if I shut down the iPad and return to the page later (via a bookmark or similar), the site is broken. I have narrowed down the failure to an ASP.NET/ASP.NET AJAX issue/bug/limitation, and I'm looking for some help to progress.

Using Fiddler as a proxy server for the iPad, I have identified the following problems, when re-opening the page.

  1. My *.skin file is not properly applied. The generated style tag simply doesn't include some of the parameters specified in the *.skin file.
  2. The page does not include the MicrosoftAjaxWebForms.js file. (When working, it emits a reference to ScriptResource.axd right above all of the ToolkitScriptManager scripts.
  3. The page does not include a reference to another js file starting with function WebForm_FindFirstFocusableChild(control)
  4. The page does not include a few hidden fields such as __LASTFOCUS, __EVENTTARGET and __EVENTARGUMENT
  5. The page doesn't include a script block using document.forms['aspnetForm'] and defining __doPostBack.
  6. The page doesn't include a script block executing Sys.WebForms.PageRequestManager._initialize
  7. A few other initialization scripts are not present (setting focus, creating updateprogress, etc.)

Somehow, it appears the framework decides that it isn't doesn't need these scripts and doesn't emit them. Given all the scripts are interrelated, there must be a common reason. This may be related to the reason that the *.skin properties are not included. Any ideas? I would have thought about browser capabilities, but this only happens on subsequent visits to the site, not the first.

Edit: Definitely looking like a browser capability issue.

Requests that work: User-Agent: Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2

Requests that don't: User-Agent: Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Mobile/8J2

Will attempt creating a custom file in App_Browsers and post back with extra info.

like image 1000
Jason Kealey Avatar asked May 20 '11 13:05

Jason Kealey


2 Answers

The root issue is indeed ASP.NET recognizes the iPad as a generic downlevel 'Mozilla' instead of Safari, when the application is loaded in full screen mode. It thinks JavaScript is not supported, etc.

The solution is adding the following to all of your ASP.NET pages (by adding this to the base page all your ASP.NET pages derive from).

    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.UserAgent != null && Request.UserAgent.IndexOf("AppleWebKit", StringComparison.CurrentCultureIgnoreCase) > -1)
        {
            this.ClientTarget = "uplevel";
        }
    }

(I tried creating a single *.browser file but failed miserably as it doesn't appear I can reference the framework's *.browser files from within my own.)

like image 106
Jason Kealey Avatar answered Oct 20 '22 09:10

Jason Kealey


I usually do this in global.asax

void Application_BeginRequest(Object sender, EventArgs e)
{
    Request.Browser.Adapters.Clear();
}
like image 29
Serge Profafilecebook Avatar answered Oct 20 '22 09:10

Serge Profafilecebook