ASP.NET MVC packages in classic ASP (or PHP, etc.)

We have a hybrid application that still works as part of a classic ASP application over ASP.NET MVC. I would also like to use related JavaScript and styles in classic ASP.

In ASP.NET, we can make good use of caching related components, we use Script.Render, which adds a version hash to the extraction URL.

The fact is that this method, of course, is not available in classic ASP.

We can use the linked directly from html <script src="bundles/js?v=<%=version%>"/> . the version variable is a classic ASP variable used when overflowing the cache (force browser update). It changes between versions.

The problem is that if the classic ASP does not provide the correct hash for binding the request, MVC binding will return the caching: no-caching header, which tells the browser not to cache it.

Do you have any good ideas? Can this hash be computed in classic ASP? Could you talk about a bunch to enable caching without v = hash? Can v = hash be migrated from MVC at startup? We have mechanisms for transferring variables between classic ASP and MVC, but this is a hash path accessible from MVC startup code.

+6
source share
2 answers

AardVark's wild thought gave me some ideas, and I figured it out myself. The solution itself is pretty simple.

Here is a solution for those who might need a similar solution.

After you have registered packages in ASP.NET MVC (Global.asax.cs or BundleConfig):

  List<string> bundleHtml = new List<string>(); bundleHtml.Add(Scripts.Render("~/bundles/legacybase").ToString()); bundleHtml.Add(Styles.Render("~/styles/legacycss").ToString()); File.WriteAllLines(Server.MapPath("~/dyn_legacy_bundle.inc"), bundleHtml, System.Text.Encoding.UTF8); 

This will create a dyn_legacy_bundle.inc file that contains the correct <script> -tags that include the hash versions (or debug versions if debug is enabled).

In classic ASP (or some weird PHP, etc.):

 <head> <!--#include file="dyn_legacy_bundle.inc" --> </head> 

Then, the file that was generated when ASP.NET was launched will be used, and use the associated css / javascript.

The negative thing is that if linked files change at runtime, this dynamic file is not updated. This will result in packets not being cached. Utilization of the application pool will ultimately fix caching, so I think we will live with it. Let me know if you understand how to avoid this.

Please note that this will work with any other structure (e.g. PHP)

+3
source

Another option:

Handler settings (i.e. Bundles.ashx)

  public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/html"; context.Response.Write(System.Web.Optimization.Styles.Render("~/css")); } 

From php:

 echo file_get_contents("http://example.com/Bundles.ashx"); 

You can use the query to specify different packages.

+1
source

All Articles