Search code examples
wcfasp.net-4.0routesscriptresource.axd

"ASP.NET Ajax client-side framework failed to load" with WCF - tried everything, still getting it


I now get the "ASP.NET Ajax client-side framework failed to load." javascript error in my asp.net 4 web site as soon as I run it (open the login page).

It used to only happen after I hit Ctrl-F5 (refresh page and all images/stylesheets/scripts) in browser while debugging.

My app uses asp.net 4 (originally written on 1.1 or 2), WCF, JsTree, some Telerik controls and MS AJAX extensions/toolkit.

In several days of googling, I found a large number of solutions given by people with the same problem (including ones here on SO and Telerik's help forums):

I tried the following, none worked for me:

  • Tried putting a ToolkitScriptManager on the page instead of a ScriptManager
  • Going to "Programs and Features" control panel and doing a "repair" on "Microsoft .net framework 4 Client profile" and "Microsoft .net framework 4 Extended"
  • Moving the ScriptManager to the bottom of the page
  • In Web.config, setting compilation debug="false"
  • Started a new ASP.NET 4 project, added and updatedpanel to a page, looked at the web.config and tried to make my web.config look more like it
  • Checked the PC's system date was correct
  • used location elements in my web.config to allow unauthenticated access to WebResource.axd, ScriptResource.axd and Telerik.Web.UI.WebResource.axd (I have Telerik controls in this site)
  • Added routes.Ignore("{resource}.axd/{*pathInfo}"); to my route registration in global.asax

Any other solutions to this problem?

I can post web.config or code if needed.

Update 1: More info
I looked at what was happening using firebug's "net" tab. GET requests for ScriptResource.axd and Webresource.axd are all failing with 404. Does this shed any further light on the issue?

Update 2: Partial solution? I used source control history to revert web.config back to before I added a WCF service to the website. The web.config that finally worked was just before I added this:

<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="FoldersAspNetAjaxBehavior">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
        <service name="Folders">
            <endpoint address="" behaviorConfiguration="FoldersAspNetAjaxBehavior" binding="webHttpBinding" contract="Folders" />
        </service>
    </services>
</system.serviceModel> 

...and removed the associated routing line from my global.asax:

routes.Add(new System.ServiceModel.Activation.ServiceRoute("", new System.ServiceModel.Activation.WebServiceHostFactory(), typeof(Folders)));

So one or both of those were the culprit. Can anyone suggest how a WCF service or it's routing could have caused this MS Ajax error?

This is my first ever WCF service. I barely understand what the above code is doing, but I'm suspecting a routing issue is at the heart of the problem somewhere...

Alternately - can anyone suggest an alternative to WCF? I can live without it if I can get my JSON data delivered to jquery another way. HttpHandler maybe, or WebService, or webform that spits out JSON as a response.write or something?

Update 2: Routing
Looks like the routing stuff in global.asax needed for the WCF service is the problem (see above). Commenting out that one line seems to fix the problem. Going to try changing the route path...

Solved: I solved it myself, see my accepted answer, but surely couldn't have done it so quickly without suggestions along the right track by some very insightful answers, thank you all.


Solution

  • In my case, what actually fixed it was changing how I called the WCF service.

    From tutorials I read on WCF, I missed the fact that I didn't need routing in the Global.asax to call the web service, and I could just call it like:

    http://localhost/myWebApp/WcfService.svc/MethodName?param=value

    (I had been relying on the routing in global.asax to let me call it like this: http://localhost/myWebApp/MethodName?param=value . I got rid of the routing and used the above way instead, and the problem disappeared)

    Thanks all for insightful answers.