Inheritance: System.Web.UI.Page, IHttpHandler, IRequiresSessionState
コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="resourceName"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static string GetWebResourceUrl(Type type, string resourceName)
        {
            if (resourceName.StartsWith(ResourceManager.ASSEMBLYSLUG) && ExtNetTransformer.CleanResourceUrl && ResourceHandler.HasHandler())
            {
                string buster = (resourceName.EndsWith(".js") || resourceName.EndsWith(".css")) ? "?v=".ConcatWith(ResourceManager.CacheBuster) : "";

                string url = "~{0}/ext.axd{1}".FormatWith(resourceName.Replace(ResourceManager.ASSEMBLYSLUG, "").Replace('.', '/').ReplaceLastInstanceOf("/", "-"), buster);

                return(ExtNetTransformer.ResolveUrl(url));
            }

            return(HttpUtility.HtmlAttributeEncode(CachedPageInstance.ClientScript.GetWebResourceUrl(type, resourceName)));
        }
コード例 #2
0
        public override void ProcessRequest(HttpContext context)
        {
            this.context = context;

            string file = this.context.Request.RawUrl;

            bool isInitScript = file.Contains("extnet/extnet-init-js/ext.axd?");

            if ((!isInitScript && !ResourceHandler.IsSourceModified(context.Request)) || (isInitScript && !string.IsNullOrEmpty(context.Request.Headers["If-Modified-Since"])))
            {
                context.Response.SuppressContent   = true;
                context.Response.StatusCode        = 304;
                context.Response.StatusDescription = "Not Modified";
                context.Response.AddHeader("Content-Length", "0");
                return;
            }

            this.SetResponseCache(context);

            if (isInitScript)
            {
                string key = file.RightOfRightmostOf('?');

                if (key.IsNotEmpty())
                {
                    try
                    {
                        string script = this.context.Application[key].ToString();
                        this.context.Session.Remove(key);
                        CompressionUtils.GZipAndSend(script);
                    }
                    catch (NullReferenceException)
                    {
                        throw new InitializationScriptNotFoundException("The Ext.NET initialization script was not found.");
                    }
                }
            }
            else
            {
                try
                {
                    this.sm       = new ResourceManager();
                    this.compress = CompressionUtils.IsGZipSupported && this.sm.GZip;

                    this.SetWebResourceName(file);

                    this.stream = this.GetType().Assembly.GetManifestResourceStream(this.webResource);
                    string ext = this.webResource.RightOfRightmostOf('.');
                    this.compress = this.compress && !this.IsImage(ext);

                    switch (ext)
                    {
                    case "js":
                        this.WriteFile("text/javascript");
                        break;

                    case "css":
                        this.WriteFile("text/css");
                        break;

                    case "gif":
                        this.WriteImage("image/gif");
                        break;

                    case "png":
                        this.WriteImage("image/png");
                        break;

                    case "jpg":
                    case "jpeg":
                        this.WriteImage("image/jpg");
                        break;
                    }
                }
                catch (Exception e)
                {
                    string s = this.IsDebugging ? e.ToString() : e.Message;
                    context.Response.StatusDescription = s.Substring(0, Math.Min(s.Length, 512));
                    this.context.Response.Redirect(Page.ClientScript.GetWebResourceUrl(this.sm.GetType(), this.webResource));
                }
                finally
                {
                    if (this.stream != null)
                    {
                        this.stream.Close();
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="resourceName"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static string GetWebResourceUrl(Type type, string resourceName, MVC.MvcResourceManagerConfig config)
        {
            if (resourceName.StartsWith(ResourceManager.ASSEMBLYSLUG) && config.CleanResourceUrl && ResourceHandler.HasHandler())
            {
                string buster = (resourceName.EndsWith(".js") || resourceName.EndsWith(".css")) ? "?v=".ConcatWith(ResourceManager.CacheBuster) : "";

                var url = "~{0}/ext.axd{1}".FormatWith(resourceName.Replace(ResourceManager.ASSEMBLYSLUG, "").Replace('.', '/').ReplaceLastInstanceOf("/", "-"), buster);
                return(System.Web.Mvc.UrlHelper.GenerateContentUrl(url, new HttpContextWrapper(HttpContext.Current)));
            }

            return(HttpUtility.HtmlAttributeEncode(CachedPageInstance.ClientScript.GetWebResourceUrl(type, resourceName)));
        }