コード例 #1
0
    void context_PostRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpContext context = ((HttpApplication)sender).Context;

        if (context.CurrentHandler is Page)
        {
            PageOptimizer.Compress(context);
        }
    }
コード例 #2
0
ファイル: CssCompressor.cs プロジェクト: BlackMoon/logread
    public void ProcessRequest(HttpContext context)
    {
        if (!string.IsNullOrEmpty(context.Request.QueryString["stylesheets"]))
        {
            string[] relativeFiles = context.Request.QueryString["stylesheets"].Split(',');
            string[] absoluteFiles = new string[relativeFiles.Length];

            for (int i = 0; i < relativeFiles.Length; i++)
            {
                string file = relativeFiles[i];
                if (file.EndsWith(".css"))
                {
                    file = file.Replace("#ThemePath#", "Resources_Design/" + ApplicationManager.GetProjectName());

                    string absoluteFile = context.Server.MapPath(file);
                    WriteContent(context, absoluteFile);
                    absoluteFiles[i] = absoluteFile;
                }
            }

            SetHeaders(context, absoluteFiles);
            PageOptimizer.Compress(context);
        }
    }
コード例 #3
0
    /// <summary>
    /// Enables processing of HTTP Web requests by a custom
    /// HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
    /// </summary>
    /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides
    /// references to the intrinsic server objects
    /// (for example, Request, Response, Session, and Server) used to service HTTP requests.
    /// </param>
    public void ProcessRequest(HttpContext context)
    {
        string        root       = context.Request.Url.GetLeftPart(UriPartial.Authority);
        string        path       = context.Request.QueryString["path"];
        string        content    = string.Empty;
        List <string> localFiles = new List <string>();

        if (!string.IsNullOrEmpty(path))
        {
            string[] scripts = path.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string script in scripts)
            {
                content += "/*---" + script + "---*/";
                // We only want to serve resource files for security reasons.
                if (script.Contains("Resource.axd") || script.Contains("asmx/js") || script.StartsWith("http", StringComparison.OrdinalIgnoreCase))
                {
                    content += RetrieveRemoteScript(root + script) + Environment.NewLine;
                }
                else
                {
                    content += RetrieveLocalScript(script, localFiles) + Environment.NewLine;
                }
            }


            //content = StripWhitespace(content);
        }

        if (!string.IsNullOrEmpty(content))
        {
            context.Response.Write(content);
            SetHeaders(context, localFiles.ToArray());

            PageOptimizer.Compress(context);
        }
    }