PDA

View Full Version : ResourceManager's RenderScripts = File throws 'Ext' is undefined



RaphaelSaldanha
Jan 04, 2015, 9:56 AM
Setting ResourceManager's RenderScripts to File throws the following exception:

'Ext' is undefined


<ext:ResourceManager runat="server" RenderScripts="File" ScriptMode="Debug" />

anup
Jan 05, 2015, 10:14 AM
I have had the same problem, but from a different scenario:

For me, using latest version from SVN causes this same error, regardless of the RenderScripts value. Instead for me it only works if cleanResourceUrl is disabled.

Further info:



Using the version from NuGet works without problems. Could there be some regression between NuGet version and latest?
I say latest but noticed this since around 22nd December - only reporting now because of the holidays in the way, sorry!
Creating a similar project (empty Web Application with MVC, Web Forms and Web API - all latest versions against .NET 4.5) and then adding reference to the Ext.NET DLLs (including utilities, transformer etc) and applying the same web.config, global.asax etc doesn't work.


In a bit more detail:

I've tried to look at many things like global.asax, app start and also trying to get my web.config down to bare minimum and I've not had any luck...

Here is what I have (a copy/paste from the one created by NuGet I think, possibly with some additional changes after that):

web.config



<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Ext.Net" />
<add namespace="Ext.Net.MVC" />
</namespaces>
<controls>
<add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" />
</controls>
</pages>
<httpHandlers>
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
</httpHandlers>
<httpModules>
<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
</httpModules>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" />
</modules>
<handlers>
<add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
</handlers>
</system.webServer>

<extnet theme="Gray" scriptMode="Debug" />
</configuration>


global.asax



public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Registe r);
RouteConfig.RegisterRoutes(RouteTable.Routes);
ExtNetConfig.RegisterRoutes(RouteTable.Routes);
}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
// Skip authenticating all ext.axd embedded resources (.js, .css, images)
if (HttpContext.Current.Request.FilePath.EndsWith("/ext.axd"))
{
HttpContext.Current.SkipAuthorization = true;
}
}
}


ExtNetConfig (note it is called from global.asax unlike the NuGet version which uses WebActivator)



public static class ExtNetConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
// Ignore all ext.axd embedded resource paths
routes.IgnoreRoute("{extnet-root}/{extnet-file}/ext.axd"); // NuGet uses this
routes.IgnoreRoute("{exclude}/{extnet}/ext.axd"); // some examples use this... Hence I have added both for now...

// Add http://example.com/extnet/ Route
routes.MapRoute(
"ExtNet", // Route name
"extnet/{action}/{id}", // URL with parameters
new { controller = "ExtNet", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
}


With the above, I use the default Ext.NET.default.aspx that comes with NuGet and it fails with this error in the browser console:



"NetworkError: 404 Not Found - http://localhost:8124/extjs/ext-all-js/ext.axd?v=21110"
"NetworkError: 404 Not Found - http://localhost:8124/extnet/extnet-all-js/ext.axd?v=21110"
ReferenceError: Ext is not defined


So Ext is not defined because the ext.axd resource is returning not found.

Note, these settings/code changes noted above were duplicated from the NuGet version which works. I have tinkered with them trying to get them to work so maybe I have missed something. The main differences are that
- Global.asax I invoked the ExtNetConfig manually
- Web.config I don't have/need a runtime section

In addition, the above code DOES work, if the following change is made:

Disable cleanResourceUrl in web.config:



<extnet scriptMode="Debug" cleanResourceUrl="false" />


So it feels like I have set it up right (I can't spot anything I have missed).

Is this a regression between the NuGet version and SVN version? (If it helps, I had this problem around 22nd December as well - but after a few days holiday only now going back to it.)

RaphaelSaldanha
Jan 05, 2015, 11:05 AM
Anup, i also tried to figure out what is going on, but unfortunately with no success.

Thank you for sharing so valuable information regarding this issue. It's gonna be useful for addressing the issue.

I will keep you posted about any update.

Dimitris
Jan 05, 2015, 4:07 PM
@RaphaelSaldanha

confirmed in IE. FF works ok.

RaphaelSaldanha
Jan 14, 2015, 1:27 PM
I confirm that this issue is still reproducible on version 3.1.0.

Daniil
Jan 22, 2015, 1:01 PM
Hello everybody,

I think here are two different issues discussed in this thread.

Raphael, RenderScripts="File" assumes that you have manually put the required Ext.NET JavaScript files into a folder inside your application. Please clarify have you done that?

Anup, I were able to reproduce the issue and a solution is something interesting. This recent post (that stuck in my mind) regarding a very different issue helped me to find a solution quickly.
http://forums.ext.net/showthread.php?50781&p=235521&viewfull=1#post235521

Please try to remove this from the <system.web> section in Web.config.

<httpHandlers>
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false"/>
</httpHandlers>

It starts working for me if remove.

It looks that having HTTP handlers (and, probably, modules) defined in both the sections - <system.web> and <system.webServer> - might cause very frustrating and hard-to-find-and-solve issues. It is lucky that I had that post (in the other thread) before working on the issue in this thread.

Here is a very relevant article written by Dave Donaldson.
http://arcware.net/use-a-single-web-config-for-iis6-and-iis7

As a summary, he tells that HTTP handlers and modules must not be defined in both the sections - <system.web> and <system.webServer> and you should have two different Web.configs for IIS6 and IIS7. Though, there is a trick to have the only Web.config. The trick is to set up this:

<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>

As far as I can see we have such an option in our Web.configs, but issues still happens. So, probably, it is best to avoid having HTTP handlers and modules in both the sections.

I am going to write a follow-up comment for the Dave's article. Maybe, he will shed some light on this issue or, maybe, would like to investigate if he doesn't have that light to shed:)

Also a small clarification why it works with cleanResourceUrl="false". In this case, the default WebResource.axd is used and, apparently, it handles the situation.

anup
Jan 22, 2015, 5:07 PM
Daniil,

Thanks. Removing that handler from system.web did the trick.

The thing I don't get is that this was not a necessary step for me if I installed from NuGet (and had the exact same web.config!) When I first posted the problem, the version from SVN and from NuGet were not that far apart, either.

Also, my production project which I am migrating up to 3.x also doesn't have this problem and it has this handler in the system.web section.

Still, good to know. Thanks for the additional details and links.

anup
Jan 22, 2015, 5:16 PM
Daniil, I spoke a bit too soon.

While certainly removing that handler helped, I now notice that whether I use cleanResourceUrl="false" or "true" makes no difference: the script links produced are always pointing to webresource.axd.

Other than much longer URLs is there any important difference?

I remember a long time ago there was something about potentially the webresource.axd one resulting in multiple instance of the same code being loaded more than once, whereas somehow the clean resource URLs didn't do that, but I can't find that thread any more...

Daniil
Jan 22, 2015, 6:23 PM
The thing I don't get is that this was not a necessary step for me if I installed from NuGet (and had the exact same web.config!) When I first posted the problem, the version from SVN and from NuGet were not that far apart, either.

Hard to say what is causing the difference.


Also, my production project which I am migrating up to 3.x also doesn't have this problem and it has this handler in the system.web section.

Maybe, it is something with IIS Express? Or some other differences between exact IIS instances and its settings.



While certainly removing that handler helped, I now notice that whether I use cleanResourceUrl="false" or "true" makes no difference: the script links produced are always pointing to webresource.axd.


That means that Ext.NET resource handler is probably not attached somehow.


Other than much longer URLs is there any important difference?

Our resource handler provides auto caching and gzipping, at least. You could review the code to investigate in details.

Ext.Net\Core\ResourceHandler.cs

Daniil
Jan 23, 2015, 9:11 AM
It looks like, at least, that we should remove or comment out the definitions of HTTP handlers and modules for IIS 6 in our Web.configs. Created an Issue:
https://github.com/extnet/Ext.NET/issues/650

anup
Jan 23, 2015, 2:53 PM
Whether I use IISExpress, or IIS (I normally use IIS only) I see the same odd behaviour across all project combinations I mentioned earlier... Very strange :)

WebResource.axd also provides gzip and caching from what I can see in the http headers (sends gzipped + last modified and related headers to help with caching).

If time allows, maybe on the weekend I will try again with latest code and a brand new project.

Daniil
Jan 23, 2015, 3:15 PM
WebResource.axd also provides gzip and caching from what I can see in the http headers (sends gzipped + last modified and related headers to help with caching).

Maybe, our resource handler appeared before the time when WebResource.axd started to cache and gzip resources by default.

For example, there is a question how to enable those features for WebResource.axd.
http://stackoverflow.com/questions/9595431/is-it-possible-to-gzip-the-automatically-included-scripts

anup
Jan 25, 2015, 3:54 PM
Yes. fair point.

I've just got latest code from SVN and rebuilt. I've updated my web.config to comment out the modules/handlers for system.web.

While it all works, the resources loaded are webresource.axd not the cleaner ext.axd, regardless of whether I use cleanResourceUrl="true" or not:

Am I missing anything here (it should be barebones, other than what is needed for ASP.NET MVC, Web Forms, Web API and Ext.NET



<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Ext.Net" />
<add namespace="Ext.Net.MVC" />
</namespaces>
<controls>
<add assembly="Ext.Net" namespace="Ext.Net" tagPrefix="ext" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="true" />
<modules runAllManagedModulesForAllRequests="true">
<add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<remove name="DirectRequestHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
</handlers>
</system.webServer>

<extnet theme="Gray" licenseKey="** Ext.NET LICENSE KEY HERE **" scriptMode="Debug" cleanResourceUrl="true" />
</configuration>


(I also set <validation validateIntegratedModeConfiguration="true" /> as that is now possible, having removed the modules/handlers from system.web - and with that as true or false doesn't change anything from what I am seeing, either)

And it is regardless whether I run in IIS (in an integrated pipeline app pool) or IIS Express (using Visual Studio defaults)

Daniil
Jan 27, 2015, 10:12 AM
Anup, please set a breakpoint on the line 409 within the HasHandler method Ext.Net\Core\ResourceHandler.cs and debug. A HasHandler call is supposed to return true with the Ext.NET resource handler is attached, otherwise - false. Debugging that method might end up with some clues what is wrong.

anup
Jan 27, 2015, 10:48 AM
Thanks for that Daniil.

I think I understand a bit more now.

Also, I was able to reproduce it with MVC Examples Explorer project that is part of the solution from SVN.

If I run it as is, it uses the Ext.NET resource handler (ext.axd URLs appear)

If I remove the handlers/modules from system.web then it ends up using WebResource.axd.

I looked at the code you pointed me to, and this is what I have:



[Description("")]
public static bool HasHandler()
{
if (HttpContext.Current.Application["Ext.Net.HasHandler"] != null)
{
return (bool)HttpContext.Current.Application["Ext.Net.HasHandler"];
}

bool result = false;
string path = Path.Combine(HttpContext.Current.Request.PhysicalA pplicationPath, "web.config");
XmlTextReader reader = new XmlTextReader(new StreamReader(path));

try
{
if (reader.ReadToFollowing("httpHandlers"))
{
if (reader.ReadInnerXml().Contains("type=\"Ext.Net.ResourceHandler\""))
{
result = true;
}
}
}
catch
{
result = false;
}
finally
{
reader.Close();
}

HttpContext.Current.Application["Ext.Net.HasHandler"] = result;

return result;
}

What I was seeing was the the reader.ReadToFollowing is failing and jumping straight into the finally block.

That is because it is trying to find httpHandlers, which of course has now been removed.

So perhaps as part of removing this from web.config where IIS6 is not needed, this code needs extending to check the handler from the system.webserver section instead?

anup
Jan 27, 2015, 11:04 AM
Some further info:

I edited the resource handler locally to look for "handlers" instead, and the page loaded blank.

Looking at the source, I see links to the CSS and JavaScript created correctly, e.g.



<link type="text/css" rel="stylesheet" href="/Ext.NET 3 Tests/extjs/packages/ext_theme_gray/build/resources/ext-theme-gray-all-embedded-css/ext.axd?v=19727" id="ext-theme" />
<link type="text/css" rel="stylesheet" href="/Ext.NET 3 Tests/extnet/resources/css/extnet-all-debug-embedded-css/ext.axd?v=19727" id="extnet-styles" />
<script type="text/javascript" src="/Ext.NET 3 Tests/extjs/ext-all-debug-js/ext.axd?v=19727"></script>
<script type="text/javascript" src="/Ext.NET 3 Tests/extjs/packages/ext_theme_gray/build/ext-theme-gray-debug-js/ext.axd?v=19727"></script>
<script type="text/javascript" src="/Ext.NET 3 Tests/extnet/extnet-all-debug-js/ext.axd?v=19727"></script>
<script type="text/javascript" src="/Ext.NET 3 Tests/extnet/locale/ext-locale-en-GB-debug-js/ext.axd?v=19727"></script>

But the page is just blank.

Note
- The CSS links return CSS
- The two -all-debug.js files return 404 not found
- The other JS files are loaded.

Because the main Ext JS file is not loaded (404) we get the original Ext is undefined error...

Hopefully that helps?

Daniil
Jan 29, 2015, 12:12 PM
So perhaps as part of removing this from web.config where IIS6 is not needed, this code needs extending to check the handler from the system.webserver section instead?

Exactly! Thank you for spotting that! Created an Issue:
https://github.com/extnet/Ext.NET/issues/661

Fixed in all the versions:
v1: revision 6285 (branches/1).
v2: revision 6286 (branches/2). It goes to 2.5.4.
v3: revision 6287 (trunk). It goes to 3.1.0 beta.


The two -all-debug.js files return 404 not found

Hmm, I cannot reproduce that.

Tested with only a <system.webServer> <handlers> section in Web.config and IIS Express.

The resources links are rendered as follows:

<link type="text/css" rel="stylesheet" href="/extjs/packages/ext_theme_gray/build/resources/ext-theme-gray-all-embedded-css/ext.axd?v=26410 (http://forums.ext.net/view-source:http://localhost:51584/extjs/packages/ext_theme_gray/build/resources/ext-theme-gray-all-embedded-css/ext.axd?v=26410)" id="ext-theme" /> <link type="text/css" rel="stylesheet" href="/extnet/resources/css/extnet-all-debug-embedded-css/ext.axd?v=26410 (http://forums.ext.net/view-source:http://localhost:51584/extnet/resources/css/extnet-all-debug-embedded-css/ext.axd?v=26410)" id="extnet-styles" /> <script type="text/javascript" src="/extjs/ext-all-debug-js/ext.axd?v=26410 (http://forums.ext.net/view-source:http://localhost:51584/extjs/ext-all-debug-js/ext.axd?v=26410)"></script> <script type="text/javascript" src="/extjs/packages/ext_theme_gray/build/ext-theme-gray-debug-js/ext.axd?v=26410 (http://forums.ext.net/view-source:http://localhost:51584/extjs/packages/ext_theme_gray/build/ext-theme-gray-debug-js/ext.axd?v=26410)"></script> <script type="text/javascript" src="/extnet/extnet-all-debug-js/ext.axd?v=26410 (http://forums.ext.net/view-source:http://localhost:51584/extnet/extnet-all-debug-js/ext.axd?v=26410)"></script>
and all of them are loaded for me.

You could debug the ResourceHandler's ProcessRequest method. It might clarify something.

anup
Feb 03, 2015, 1:00 PM
I finally got a moment to look into this further.

I have resolved it now. What I found was this:

I went back to view source on the browser for the page failing to load the Ext JS and Ext.NET all debug scripts. In the view source I clicked on the link to the actual script include, as the browser shows the source of the link you clicked. As before, I saw the custom 404 page I had set up. What I didn't notice last time (as it was off the screen) was at the bottom was this commented out bit:



<!--
[HttpException]: A public action method 'extnet-all-debug-js' was not found on controller 'Ext.Net3.Tests.Controllers.ExtNetController'.
at System.Web.Mvc.Controller.HandleUnknownAction(Stri ng actionName)
at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsy ncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Controller.EndExecuteCore(IAsyncRes ult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsy ncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsy ncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.HttpApplication.CallHandlerExecutionSte p.System.Web.HttpApplication.IExecutionStep.Execut e()
at System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously)
-->

This made me realise that it must be something to do with the routing setup/global.asax/registering routes etc.

I compared to the NuGet version which uses WebActivatorEx. I don't have that in my test project. And without adding it, it was still not working.

I double checked global.asax (as I was just registering the route manually without the use of WebActivatorEx).

ExtNetConfig looks the same other than lack of the Start method that WebActivatorEx used.

So it was global.asax:



void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Registe r);
RouteConfig.RegisterRoutes(RouteTable.Routes);
ExtNetConfig.RegisterRoutes(RouteTable.Routes);
}


The above wasn't working. And then I realized. The ExtNetConfig registration has to come before the general route config registration.

Simply swapping those lines around to the following worked:



void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Registe r);
ExtNetConfig.RegisterRoutes(RouteTable.Routes);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}


So I think the summary is that in a manually created project that referenced Ext.NET DLLs manually (i.e. not via NuGet) I didn't have WebActivatorFx. Registering the route using the ExtNetConfig was added manually after the default route registration (which is not right). While this took a while to spot (though slap on the head moment!) it helped lead to a leaner web.config :)

Hope that helps others!

Daniil
Feb 12, 2015, 10:21 AM
Hi Anup,

Nice caught! And thank you for the detailed explanation as usual. I will keep it in mind as well!

From my best understanding, you are not expecting we should correct something in Ext.NET, aren't you?:)

anup
Feb 12, 2015, 12:20 PM
That's right Daniil - not expecting any changes from you.

(I don't know if I ended up hijacking the original issue or if it was the same thing - if that can be confirmed, this post could be closed)

Daniil
Feb 12, 2015, 3:09 PM
(I don't know if I ended up hijacking the original issue or if it was the same thing - if that can be confirmed, this post could be closed)

Sorry, Anup, I don't understand clearly. What are you considering as the original issue?

anup
Feb 12, 2015, 3:26 PM
I meant to say Raphael's original post in this thread specifically talked about using
RenderScripts="File"

I had Ext is undefined with or without that.

So maybe Raphael, if you can confirm that what I mentioned about how to resolve this, if that works for you then we could close this thread?