cassette.axd refuses to work - 404 File or directory not found

884 views
Skip to first unread message

voithos

unread,
Sep 17, 2012, 6:23:29 PM9/17/12
to cass...@googlegroups.com
This is quite odd. I've tried numerous things, none of which work.

I'm trying to use Cassette with an ASP.NET web forms projects, and it's working very well. On my local environment (IIS Express). Unfortunately, as soon as I deploy it to our test servers (in Amazon's EC2), it stops working as expected. I believe we're using IIS 7 in the cloud.

There are a couple of symptoms: first, cassette.axd (as in, the web UI) no longer works - it fails with a 404 file or directory not found. I'm fairly sure that the modules and handlers configuration is correct (since it works fine in my local environment), and I'm also fairly sure that .axd handlers are working in general, since I'm using other projects (like ELMAH and Glimpse) which use such handlers. But cassette.axd console 404's consistently. The odd part is that normal asset bundling and compression off of the cassette.axd path functions. Our JS and CSS files are compressed (using the AJAX minifier) and the URL is off of the /cassette.axd handler.

Second, the compression works incorrectly. The AJAX minifier breaks some of our code, so we decided to configure the YUI minifier instead, using a class that implements from IJavaScriptMinifier. Unfortunately, in the test environment, cassette seems to completely ignore our configuration, and uses the AJAX minifier anyway. I'm not sure if it matters, but we're using "dynamic" compilation via App_Code.

Can anyone think of a reason why this is happening?

Here's an excerpt from our Web.config:
        <cassette debug="false" />
        <system.diagnostics>
            <sources>
                <source name="Cassette" switchName="CassetteSwitch" switchType="System.Diagnostics.SourceSwitch" />
            </sources>
            <switches>
                <add name="CassetteSwitch" value="All" />
            </switches>
        </system.diagnostics>
        <system.web>
            <httpModules>
                <add name="CassetteHttpModule" type="Cassette.Aspnet.CassetteHttpModule,Cassette.Aspnet" />
            </httpModules>
            <httpHandlers>
                <add path="cassette.axd" verb="*" type="Cassette.Aspnet.CassetteHttpHandler,Cassette.Aspnet"/>
            </httpHandlers>
        </system.web>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true">
                <add name="CassetteHttpModule" type="Cassette.Aspnet.CassetteHttpModule, Cassette.Aspnet" />
            </modules>
            <handlers>
                <add name="CassetteHttpHandler" path="cassette.axd" verb="*" allowPathInfo="true"
                    type="Cassette.Aspnet.CassetteHttpHandler, Cassette.Aspnet"/>
            </handlers>
        </system.webServer>

Andrew Davey

unread,
Sep 17, 2012, 6:33:28 PM9/17/12
to cass...@googlegroups.com
When debug=false then diagnostic UI at /cassette.axd is not available by default. To enable this add the following attribute in web.config:


<cassette allowRemoteDiagnostics="true"/>

Re minification:
What version of AjaxMin are you using that is breaking your code?
For the YUI minifier, how are you configuring the custom IJavaScriptMinifier?

voithos

unread,
Sep 17, 2012, 6:44:41 PM9/17/12
to cass...@googlegroups.com
Ah! It was something so simple. Thanks!

In regards to the minifier, I'm believe I'm using v4.46. In fact, I tried using the most recent stable release, and Cassette threw an assembly reference error, asking for v4.46.

As for the IJavaScriptMinifier, here's the configuration:
    /// <summary>
    /// Services class which configures Cassette's minifier.
    /// </summary>
    public class CustomCassetteServices : IConfiguration<TinyIoCContainer>
    {
        public void Configure(TinyIoCContainer container)
        {
            // Use the YUI minifier
            container.Register<IJavaScriptMinifier>(new YuiJavaScriptMinifier());
        }
    }

    public class YuiJavaScriptMinifier : IJavaScriptMinifier
    {
        public Func<Stream> Transform(Func<Stream> openSourceStream, IAsset asset)
        {
            return delegate
            {
                using (var reader = new StreamReader(openSourceStream()))
                {
                    var output = MinifyJavaScript(reader.ReadToEnd());
                    return output.AsStream();
                }
            };
        }
        
        string MinifyJavaScript(string input)
        {
            // Check of invalid input -- compressor chokes on it
            if (String.IsNullOrEmpty(input))
                return String.Empty;

            var compressor = new JavaScriptCompressor();

            // Make sure that all minifier code is non-breaking, regardless of `eval()`s
            // or other unsafe patterns
            compressor.IgnoreEval = false;

            return compressor.Compress(input);
        }
    }

Andrew Davey

unread,
Sep 17, 2012, 8:09:08 PM9/17/12
to cass...@googlegroups.com
If you don't mind a pre-release package, then Cassette 2.1.0-alpha1 depends on AjaxMin >= 4.60. Worth a try... otherwise please report the bug to the AjaxMin developers if it's still broken.

That configuration looks okay to me. You mentioned you're using App_Code - maybe that's meaning Cassette can't find the assembly. Have you tried using a regular compiled assembly instead?

voithos

unread,
Sep 18, 2012, 11:46:05 AM9/18/12
to cass...@googlegroups.com
I haven't tried precompiling an assembly, but why would it work fine in my local environment, then?

Andrew Davey

unread,
Sep 18, 2012, 12:46:39 PM9/18/12
to cass...@googlegroups.com
I don't know. It seems that Cassette's use of GetReferencedAssemblies ( http://msdn.microsoft.com/en-us/Library/system.web.compilation.buildmanager.getreferencedassemblies(v=vs.110) ) should work fine with App_Code.

When running locally with debug=false does it still work?
Are there any other significant differences between local and production?

voithos

unread,
Sep 18, 2012, 2:25:17 PM9/18/12
to cass...@googlegroups.com
Yes, in my local environment, having debug=false works fine. The configuration class gets detected properly, and it outputs the minified JS without breaking anything. Other significant differences... well, as I said, locally I'm running IIS Express, in the cloud it's IIS 7, I believe. Both are running in Integrated mode. Both on .NET 4. I can't really think of many other differences...

In the past, I recall having to rebuild Cassette's cache after making a change to the compiled configuration (even in my local environment). But in this case, even after rebuilding (via cassette.axd), the configuration is still ignored.
Reply all
Reply to author
Forward
0 new messages