Web Resources demystified: Part 3 (Troubleshooting)

by ASP.NET AJAX Team | Comments 15

In this post I will show you how to troubleshoot Web Resource related problems and how to deal with them.

If you are using an ASP.NET server control with rich client-side behavior it is likely built to utilize web resources. Sometimes your page loads and that rich server side control does not work at all - the tree view does not expand, the grid cannot sort etc. Most of the times this is because the JavaScript files of those controls have failed to load. If your browser is configured to prompt on JavaScript errors you may see the following error messages:

  1. "RadTreeView is undefined" if you are using RadControls for ASP.NET (Classic)
  2. "Sys is undefined" or "Telerik is undefined" if you are using RadControls for ASP.NET Ajax (former "Prometheus")

Receiving one of those messages indicates that there is a Web Resource related issue. The next step is to find out what exactly is causing that error message.

Manually requesting the web resource handler

The fastest way would be to view the rendered output of your page and get the URL of the offending script tag. Here is a short demo with RadTreeView Classic:

<div id="RadTreeView1_wrapper"
    <!-- 6.3.5 --><script type="text/javascript" src="/Sample/WebResource.axd?d=mOXVXvUPV2JWSrl55DXbLd4CU3OqV82yycNo3oZC9Qn3B05GrDVSd8t21hVYrCq41DKrZevSapn__c8UQPRmtdYqo9Oc7wmveT4PyIINoBOcBUJOfqTubx1YzP6v6wYp0&amp;t=633437882200000000"></script> 

Then paste that URL in your browser's address bar (after the domain and folder of course). Normally the web server should serve back the content of that web resource. However in case of a problem with the web resource HTTP handler you would see an error page saying that the server returned HTTP error code 404 (not found) or 500 (server error).

Using web development tools to request the web resource handler

Another useful technique is to use an HTTP traffic sniffer tool - Fiddler for Internet Explorer or FireBug for FireFox. Here are two screenshots showing a failed request to a web resource file:

Fiddler

image

FireBug
image

Dealing with the 404 error code (the requested URL was not found)

Please check the following:

  1. Check in the IIS management console that the .axd extension (the default HTTP handler extension) is allowed:
    image
  2. Also check if the “Verify if file exists” checkbox is unchecked. This screen appears after you click the "Edit" button appearing in the previous screenshot:

    image
  3. If you are using RadControls for ASP.NET Ajax check if the "ScriptResource.axd" HTTP handler is correctly registered in your web.config. Look for the following statement:

    ASP.NET 2.0:
    <add verb="GET,HEAD" path="ScriptResource.axd"
    type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    validate="false"/>  

    ASP.NET 3.5
  4. <add path="ScriptResource.axd" verb="GET,HEAD"
    type
    ="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" 
    validate
    ="false" /> 

    IIS7 Integrated Mode

    The following statement should be present in the <handlers> section instead of <httpHandlers>:

    <handlers> 
    <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" />   

    Note: if you are using .NET 2.0 the version of the System.Web.Extensions assembly should be "1.0.61025.0". If you are using .NET 3.5 the version should be "3.5.0.0". Always make sure you are referring to the right assembly version.
  5. If you are using RadControls for ASP.NET Ajax and RadScriptManager check if the Telerik.Web.UI.WebResource.axd HTTP handler is correctly registered in your web.config:

    ASP.NET 2.0:
    <add path="Telerik.Web.UI.WebResource.axd" verb="*"
    type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.1.619.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" 
    validate
    ="false" />  

    ASP.NET 3.5
    <add path="Telerik.Web.UI.WebResource.axd" verb="*"
    type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.1.619.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" 
    validate
    ="false" /> 

  6. IIS7

    The following statement should be present in the <handlers> section instead of <httpHandlers>:

    <handlers> 
    <add name="Telerik.Web.UI.WebResource" 
     path="Telerik.Web.UI.WebResource.axd" verb="*"  
    type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2008.1.619.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"/>   
     

    Note: The version in the HTTP handler registration statement will vary depending on the release date and .NET runtime (2.0 or 3.5). Always make sure you are referring to the right assembly version.

Dealing with the 500 error code (server error)

You should check the detailed error message. There are two common cases:

  1. "Padding is invalid and cannot be removed"
    The problem is likely to be related with the machine key. This blog post delves into why this error occurs. This MSDN article describes how to create a custom machine key.
  2. "Specified argument was out of the range of valid values. Parameter name: utcDate"
    The assembly containing the embedded resources is probably built in the future (its last modified time is later than the current time). This can occur when deploying in a different time zone. The solution is simple - run the following command line statement (the commas at the end are important!):
    copy /b <path to assembly which is built in the future>,,


I hope this helps.

,
Team Leader,
Kendo UI Team

15 Comments

Milan Negovan
We've had a similar issue with HTTP compression. Once we added WebResource.axd to the exclusion list, everything was back to normal. We used Ben Lowery's HTTP compression module.
Herve
Hi, Here is how I have fixed the "Telerik is undefined" js error if that can help anyone here... After having checked the web.config fil I have changed the application pool from DefaultAppPool to Classic .net AppPool and that's it. Without your post I was lost, many thanks
Atanas Korchev
Perhaps changing the AppPool is not the best solution. When dealing with IIS7 Itegrated mode you need to register HTTP handlers in the system.webServer/handlers section.
Dytiscus
I had the same "telerik undefined" script error, using version 2008.2.723.35. After searching for a very longtime I found a radmultipage wich had the EnableEmbeddedScripts set to false. See for an example the following link: http://www.telerik.com/community/forums/thread/b311D-baettk.aspx Greetings Carol
Stephen Masters
Another thing worth checking for if you're getting 404s. If you're running an additional security layer such as SiteMinder or URLScan, that may block access to the .axd files. A number of folks have mentioned the need to put an empty ScriptResource.axd and WebResource.axd file in the root of your app if you use SiteMinder, as that checks whether the files exist. If you're using URLScan, you might need to change the config to put the .axd extension in its white list. Steve
Cesar
You saved my day, I tried everything I found in blogs, forums and nothing worked

TY
JM
Also, make sure that if you add a wildcard application map (in Application Configuration section of IIS) for aspnet_isapi.dll, you UNCHECK the "Verify that the file exists" checkbox.  That was what was causing my "Sys is undefined" issue.
Dave
Atanas, I have a RadMenu that displays funny in  the virtual directory. It's vertically aligned whereas  I specified horizontal in development. The menu subitems also display rather than being rolled up. Can you help? I tried looking at "Manually requesting the web resource handle" but I don't have an offending script.

Thanks,

Dave
sadaf
Thanks for great post. It resolved issue quickly otherwise it would have take days.
Erik
Im using RadScriptManager but when i Debug the page i've keep getting this error:
Microsoft ASP.NET AJAX cannot be initialized!
[Break on this error] if(typeof(Sys) != "undefined"){$addH...t ASP.NET AJAX cannot be initialized!"

RadScriptManager automaticly adds the folowing javascript:

<script type="text/javascript">
//<![CDATA[ 
    if(typeof(Sys) != "undefined"){$addHandler(window, "load", function(){Sys.Application.initialize();}); } else { throw new Error("Microsoft ASP.NET AJAX cannot be initialized!")}
//]]>



Foolowed yout guide and everything where corerct but stil i get "Microsoft ASP.NET AJAX cannot be initialized!"

KAH

At least this post helped me look in the right place. Everything was put up as it should be, but whatever I did nothing seemed to solv the issue of getting the "'Telerik' is undefined" message.

FINALLY, when diving down into the code I had added this attribute to the RadTreeView control, which seemed to be the root of my problem:

EnableEmbeddedScripts="False" 
 

KAH

At least this post helped me look in the right place. Everything was put up as it should be, but whatever I did nothing seemed to solv the issue of getting the "'Telerik' is undefined" message.

FINALLY, when diving down into the code I had added this attribute to the RadTreeView control, which seemed to be the root of my problem:

EnableEmbeddedScripts="False" 
 

Hanan
thansk for all of these suggested solution, but actualy none of them worked for me as it is supposed to be, when i applied solution , i got ruined another part of the application, i feel like the telerik aren't capable of interacting with each other, and i did search to the tooth and nail to get somthing suitable to my application , no i got no where, it seems we all share with the same error but totally different secnarios.


please i just need to figure out why we are gettign some erros when we use scriptmanager instead of the ScriptManager, they are supposed to do the same functionality.
Matt
Can you update the "Dealing with the 404 error code (the requested URL was not found)" section with IIS7 extension management screen shots and instructions?  "Verify file exists" does not appear to exist in IIS7, etc. 
Sean
I just got done troubleshooting one of those 404's when migrating to IIS Express 7.5.

It might be useful to make a note somewhere that the order the handlers are defined is significant. (I'm not sure how this plays out when modifying web.config, but it can be a big problem when working directly with applicationhost.config)

In particular, the telerik handlers must be defined before the static file handler or you will forever get 404 errors. The static handler from my applicationHost.config looks as follows:

<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by ASP.NET AJAX Team - or - read latest articles in Developer Tools