Jaa


ASP.NET - AJAX functionality not working on the page | Getting ‘Sys’ is undefined

When the ASP.NET AJAX Functionality is not working on a web page, it is usually due to the fact that the javascript needed for AJAX is not sent to the client from the server for some reason.

‘Sys’ is undefined. You might see this error message when there is a problem with the client in receiving the javascript sent by the server for the AJAX functionality. Some browser might not show an alert of this error message, and you might see the status bar saying done, but in yellow. Yellow always indicates that you have an error occurred while the page was getting loaded.

clip_image002

And, when you double click on the status bar, you will see the below window depending on the version of IE you are running:

clip_image004

Internet Explorer 8

clip_image006

Internet Explorer 7

Let’s go ahead, and look at the line of script reported in the error by opening up the HTML source(right click in the browser and choose view source) sent by the server to the client, and see what’s present at the line number 47, and char 1. You will see the below:

 Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));

Interestingly this is not something which you wrote yourself on the page, but this is added at the runtime by the ASPX handler which served your page, and this is done by the server side ScriptManager you have in your ASPX page.

If you search for ‘Sys’ in your HTML source, you might not find it. Because this is something which is sent to the client from a different file which is included in the HTML source. You might see the below (with a different value for the query strings d and t) in the page:

 <script src="/AJAXTimer/ScriptResource.axd?d=9tk5luWIQHpRBi2jvaLA3ovu_ryV3iBlv84cuaA3MT--_
             e3q9KdLubgmmRoMp9ixegSpkyQ0LFGM_KxDw2qwSneq8GS2D1TcTOujL7Q85DE1&amp;t=556b0a58" 
             type="text/javascript"></script>

The browser will make a request to ScriptResource.axd at runtime. The response will be a JavaScript file that is used for ASP.NET AJAX functionality.

Let’s now see how to troubleshoot this problem. First thing to check is the IIS logs where all the requests with the corresponding response status would be logged. Below is the corresponding log for ScriptResource.axd on the server.

2009-02-26 21:00:28 W3SVC1 GET /AJAXTimer/ScriptResource.axd d=9tk5luWIQHpRBi2jvaLA3ovu_ryV3iBlv84cuaA3MT--_e3q9KdLubgmmRoMp9ixB0N1se3B9f-x_KQriM4xUb90HPABW5aUQb_PG3gbAH41&t=556b0a58 80 - 65.52.22.253 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322) royalchallenger 404 0 2 1405 567 15

So, we know for sure that the server is sending a HTTP 404 (Page not found) for the AXD request. Below are some possible reasons why a 404 might be sent from the server:

  1. File doesn’t exist on the server
  2. There is no ISAPI extension configured to serve this request
  3. An ISAPI filter plugged in the request pipeline sends a 404 for some reason
  4. URLScan rules might prevent it
  5. “Verify that file exist” is selected for the ISAPI extension configured to serve the request
  6. ISAPI Extension configured for the request (.axd in this example),is a prohibited web service extension

If you are running IIS7 (and above), you should consider using FREB for 404 errors, and from the logs you will be able to know which module is setting the 404.

If you check for a ScriptResource.axd file in your website folder, you might be surprised to find that it's not there. ScriptResource.axd isn't actually a physical file. It's a handler that is used to serve the JavaScript files necessary for AJAX functionality to the client.

In one of plenty issues I’ve worked on AJAX, my customer was having a wild card ISAPI extension which on sight was advised for removal by me as a troubleshooting step, but only after taking a backup of IIS configuration. After removing the ISAPI extension, it started working – AJAX scripts are been sent to the client without any problem.

But the ISAPI extension which my customer had seemed to allow the ASPX requests to be processed by aspnet_isapi.dll, but it wasn’t allowing .AXD requests. It was the “Verify that file exists” causing the trouble because there is no physical file called ScriptResource.axd.

clip_image002[4]

If you are running into this problem, I would like you to check for the below things on the server.

  • Check if .axd requests are mapped to the aspnet_isapi.dll

    • In IIS6, you can check this in the Website properties --> Home Directory --> Configuration
    • In IIS7, you can check this in Website Features View --> Handler Mappings
  • Check if the web.config file has handler mappings added

    • In IIS6 or (IIS7 classic mode), you might need to place this under <system.web/httpHandlers>
    • In IIS7 (integrated mode), you might need to place this under <system.webServer/handlers>
 <add verb="GET,HEAD" path="ScriptResource.axd" 
    type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0,
          Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />

You might also want to check this blog by Scott where he explains about xhtmlConformance, and problems of it with AJAX. You can choose to remove that line from the web.config, or can set the mode to “Transitional” instead of “Legacy”.

Comments

  • Anonymous
    March 01, 2009
    Hey man, followed your steps as much as I could and refered this URL to my host, indeed 404s are being returned. But I still get 'sys is undefined' after I downloaded the client libararies and set scriptpath on the script mamanger control so the code is being found. What does webResource.axd do, could that have anything to do with it.

  • Anonymous
    March 17, 2009
    Hi Dave - are you using any custom Javascript code where you refer to Sys? If so, make sure they are following the ScriptManager tag in the ASPX source.

  • Anonymous
    June 29, 2009
    The comment has been removed

  • Anonymous
    August 05, 2009
    Hi All Pls refer this http://sysisundefined.blogspot.com/2009/08/sys-is-undefined-update-panelajax.html

  • Anonymous
    August 05, 2009
    Hi Txam, We would need to take fiddler and netmon traces and look into those. May be you can open up a ticket with Microsoft Developer Support and we can help you out by analyzing those. Amit

  • Anonymous
    August 26, 2009
    The comment has been removed

  • Anonymous
    January 12, 2010
    Make sure you have this in the web.config... <!--        The system.webServer section is required for running ASP.NET AJAX under Internet        Information Services 7.0.  It is not necessary for previous version of IIS.    -->    <system.webServer>      <validation validateIntegratedModeConfiguration="false"/>      <modules>        <remove name="ScriptModule" />        <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>      </modules>      <handlers>        <remove name="WebServiceHandlerFactory-Integrated"/>        <remove name="ScriptHandlerFactory" />        <remove name="ScriptHandlerFactoryAppServices" />        <remove name="ScriptResource" />        <add name="ScriptHandlerFactory" verb="" path=".asmx" preCondition="integratedMode"             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>        <add name="ScriptHandlerFactoryAppServices" verb="" path="_AppService.axd" preCondition="integratedMode"             type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>        <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />      </handlers>    </system.webServer>

  • Anonymous
    February 10, 2010
    The comment has been removed

  • Anonymous
    May 13, 2010
    Thanx a lot For every one,Me got stuck in this issue for 2 days ..

  • Anonymous
    June 10, 2010
    Thanks Michael,your comment helped me to fim my issue well by simply unchecking the "Verify that file Exisits" Thanks a lot.

  • Anonymous
    July 02, 2010
    I'm using .net v4 and the config is different and none of this helps.  The error happens only on the corporate LAN and not the public Internet.  Security?  It started with .net 4.  

  • Anonymous
    September 16, 2010
    I am facing same 'sys' error  only on my server side code.

  • Anonymous
    September 23, 2010
    The Solution for IIS7 and ASP.NET 3.5 is this: you must register the ScriptResource.axd in Handler Mappings in IIS7 Manager