views:

1477

answers:

2

I'm using the new CompositeScript feature that's available in the ASP.NET 3.5 SP1 for the ScriptManager.

When I test this with the ASP.NET Development Server it works fine but when I publish the site to my IIS webserver the combined files cannot be downloaded, I always get the following error: Invalid ViewState.

The querystring that is added to the ScripResourceHandler is quite long (cause??):

<script type="text/javascript" src="/ScriptResource.axd?d=8PM7kHuMMquT4Ta6cvC_2JLE_mKmYLeDWgV9z71Ryu5-7LRuy1v7MkEzM-M-NoE92QPDzXGBBSohhGbO17FKHqTZ9xMJx_5WaNrJTiwoFF28dlc6k02jRhN73u_Ohv7CKe-QPUdCOnzsBblNlopier7Ijd66Jp6Z0voAkZp36RzWYd64G9SOBCUs1HTu7oRQJTOlWyAd26O2r3S7Js7VX1YddtK-zO7DHa272a5-BitDkKTubnMPlwyYnW0Cn7TVK7NCjyF_o1E6wgPWY4THH56YNMtyRKeTrGFzMjTkiOmv18i2ePMHErlWYBXiL0If47bfPbNtfIeAMQAT8xX_DMBN6VR74GDlJSXQpFcGadNsKocZ4EOonDLykWf6Oq4ISr54_c-k_zzma5f6qFk1fXx8n8Vphe_QL67R-7aDlwBH9CrK-IBsuYDDeMSlTMWAZ6TRIhZSAyVANvh2VPZ8eBmGD0BpVA7D8e2vA1l6_kbC7w6CmGCEok-Cb1dqQPjgwB6Ho199M3IWrdwbUkN2leiDXn9bkZMGWA75IyjYiDisAz97JyA9AtDolhYGbxJ_AVrIpNpZFOQBZsXBkLfoo7iZmzHLwG7HNPhodtaekPAcxiKgi7Xf62DEnb20VRYMCFH8Qzfx5u4nlzZo4n7ZMkxDpWPlB65LCeCtvC6ZIl1kbq9FJ9dlf_DAkNU3-KKy__87Tzz9RWx6ucLXRGuljodLjiT8wrWRET_CpCspnHqpByBxEXiOi1_jW0e6_GjfZ9Fqk9GIXsSoTvnZmz_J68d28rSafQVKO1O06AjHCCBd7wh5mY-ISSLFaZ0pPszjdgVYxnC83ujaY9SWmRxUb_lPT4VdYG1Q02iyRO2l7BIDO-NiF77V_kklBhQRZ5ZiT3Vbf-JL6EZISThBJuh3WA2">

Does anyone know a solution to this problem?

+2  A: 

I think the link to ScriptResource.axd is invalid.

AFAIK, the querystring that is present on ScriptResource.axd is made up of two parameters (d and t). The d paramater is an encrypted string that comprises of the assembly, version number if applicable and the name of the resource (i.e. javascript file) that is embedded in said assembly. The encryption is based on the machine key. The t parameter is the date the assembly was updated (in ticks).

If you have a look at Reflector and have a look at the System.Web assembly and look at UI.Page there is a private method called DecryptString. I'm not on Windows at the mo, but if you look down DecryptString you will see that eventually you'll get an exception "Invalid viewstate".

There are a few different ways to do Composite Scripts and script combining. But I don't think any of the ScriptManager controls (AjaxToolKit has one too) have really got this down pat. In practice, I find you're always left with a few scripts outside.

A couple of other resources to consider are: Omar Al Zabir's posts at codeproject: http://www.codeproject.com/KB/aspnet/HttpCombine.aspx and http://www.codeproject.com/KB/aspnet/fastload.aspx. Omar also has a good book that covers performance.

Also on codeproject, Moiz Dhanji has a slightly different approach: http://www.codeproject.com/KB/aspnet/AspNetOptimizer.aspx.

Martin Clarke
+1  A: 

Another variation of Omar's and Moiz's approaches, pointed by Martin, is one employed by Cristian in his N2 CMS project.

The idea is that instead of describing each group of scripts in a config file, one just creates a virtual sub-folder for each group. Than, upon request, aLL a special HTTP handler has to do is to traverse requested directory and process aLL files found there.

esteewhy