Thursday, June 2, 2011

Combined CSS using handler is not working in firefox and chrome.

I am combining more than one CSS using a handler below.

<%@ WebHandler Language="C#" Class="HttpCombiner" %>

using System;
using System.Net;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Configuration;
using System.Web;

public class HttpCombiner : IHttpHandler {
    
    public void ProcessRequest(HttpContext context)
        {
        // Get the list of CSS files from QueryString.
        string files = context.Request.QueryString["fileName"];
        if (string.IsNullOrEmpty(files))
            {
                return; // If no file name is mentioned then don't proceed.
            }

        // Get the list of files specified in the querystring (joined by ',').
        string[] arrFileNames = files.Split(',');
        if ((arrFileNames != null) && (arrFileNames.Length > 0))
            {
            string filePath = string.Empty;

            // Read the content of each CSS file and write it in the response.
            for (int fileCount = 0; fileCount < arrFileNames.Length; fileCount++)
                {
                filePath = context.Server.MapPath(arrFileNames[fileCount]).Trim();
                if (File.Exists(filePath)) // Check if the file exists in the physical location or not.
                    {
                        context.Response.Write(File.ReadAllText(filePath));
                    }
                }
            //context.Response.ContentType = "text/css"; // Set the content type.
            }
        }
    public bool IsReusable
    {
        get
        {
            return true;
        }
    }
}

its working fine in IE 7.0 and above but not working in FireFox and Chrome.
when i include CSS Separately it working fine in all browsers.
any help or suggestion????

No comments:

Post a Comment