I've successfully created a module to minify asp.net default axd files that render only javascripts, but with AjaxControlToolkit I need to differentiate the content type weather it is css or image or javascript, please not that (Request/Response).ContentType is returning text/html
public class ParseAXD : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += context_BeginRequest;
}
void context_BeginRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;
var path = context.Request.Url.PathAndQuery;
if (path.ToLower().Contains(".axd") && IfNotWebClientRequest())
{
var remote = new Uri(Lib.SiteDb.DomainName + path);
using (WebClient client = new WebClient())
{
string content = client.DownloadString(remote);
//Need to identify the ContentType here, please not that (Request/Response).ContentType is returning text/html
var settings = new CodeSettings();
settings.MinifyCode = true;
settings.LocalRenaming = LocalRenaming.CrunchAll;
settings.RemoveFunctionExpressionNames = true;
settings.EvalTreatment = EvalTreatment.MakeAllSafe;
content = new Minifier().MinifyJavaScript(content, settings);
context.Response.ContentType = "text/javascript";
context.Response.Write(content);
context.Response.Cache.SetValidUntilExpires(true);
context.Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetOmitVaryStar(true);
context.Response.Flush();
context.Response.End();
}
}
}