コード例 #1
0
 /// <summary>
 /// 获得图标的服务器地址
 /// </summary>
 /// <param name="icon">图标</param>
 /// <returns>图标的服务器地址</returns>
 public static string GetIconUrl(Icon icon)
 {
     //return ResourceHelper.GetWebResourceUrl(String.Format("FineUI.res.icon.{0}", IconHelper.GetName(icon)));
     if (icon == Icon.None)
     {
         return(String.Empty);
     }
     else
     {
         return(String.Format("{0}/{1}", GlobalConfig.GetIconBasePath(), IconHelper.GetName(icon)));
     }
 }
コード例 #2
0
        /// <summary>
        /// 处理资源的请求
        /// </summary>
        /// <param name="context">Http请求上下文</param>
        public void ProcessRequest(HttpContext context)
        {
            string type      = String.Empty,
                   typeValue = String.Empty,
                   resName   = "FineUI.";


            if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["icon"]))
            {
                type = "icon";
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["js"]))
            {
                type     = "js";
                resName += "js." + typeValue;
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["lang"]))
            {
                type     = "lang";
                resName += "js.lang." + typeValue;
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["theme"]))
            {
                type     = "theme";
                resName += "res.theme." + typeValue;
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["css"]))
            {
                type     = "css";
                resName += "res.css." + typeValue;
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["img"]))
            {
                type     = "img";
                resName += "res.img." + typeValue;
            }

            byte[] binary;
            switch (type)
            {
            case "icon":
                if (!typeValue.EndsWith(".png") && !typeValue.EndsWith(".gif"))
                {
                    typeValue = IconHelper.GetName((Icon)Enum.Parse(typeof(Icon), typeValue));
                }
                //resName += "res.icon." + typeValue;
                string serverPath = String.Format("{0}/{1}", GlobalConfig.GetIconBasePath(), typeValue);
                context.Response.WriteFile(context.Server.MapPath(serverPath));

                context.Response.ContentType = "image/" + GetImageFormat(typeValue);
                break;

            case "js":
            case "lang":
                context.Response.Write(ResourceHelper.GetResourceContent(resName));
                context.Response.ContentType = "text/javascript";
                break;

            case "css":
                context.Response.Write(ResourceHelper.GetResourceContent(resName));
                context.Response.ContentType = "text/css";
                break;

            case "theme":
            case "img":
                binary = ResourceHelper.GetResourceContentAsBinary(resName);
                context.Response.OutputStream.Write(binary, 0, binary.Length);
                //context.Response.Write(ResourceHelper.GetResourceContent(resName));
                context.Response.ContentType = "image/" + GetImageFormat(resName);
                break;
            }


            // 缓存一年,只能通过改变 URL 来强制更新缓存
            context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
        }
コード例 #3
0
        /// <summary>
        /// 处理资源的请求
        /// </summary>
        /// <param name="context">Http请求上下文</param>
        public void ProcessRequest(HttpContext context)
        {
            string type          = String.Empty;
            string typeValue     = String.Empty;
            string extjsBasePath = GlobalConfig.GetExtjsBasePath();


            if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["icon"]))
            {
                type = "icon";
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["theme"]))
            {
                type = "theme";
            }
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["img"]))
            {
                type = "img";
            }
            else
            {
                context.Response.Write("Not supported!");
                return;
            }

            string filePath     = String.Empty;
            string fileBasePath = String.Empty;

            switch (type)
            {
            case "icon":
                if (!typeValue.EndsWith(".png") && !typeValue.EndsWith(".gif"))
                {
                    typeValue = IconHelper.GetName((Icon)Enum.Parse(typeof(Icon), typeValue));
                }
                fileBasePath = GlobalConfig.GetIconBasePath();
                filePath     = String.Format("{0}/{1}", fileBasePath, typeValue);
                break;

            case "theme":
                string themePath        = "";
                string themeImageFormat = "";
                int    lastDotIndex     = typeValue.LastIndexOf(".");
                if (lastDotIndex >= 0)
                {
                    themePath        = typeValue.Substring(0, lastDotIndex).Replace('.', '/');
                    themeImageFormat = typeValue.Substring(lastDotIndex + 1);
                }

                fileBasePath = String.Format("{0}/res/images", extjsBasePath);
                filePath     = String.Format("{0}/{1}.{2}", fileBasePath, themePath, themeImageFormat);
                break;

            case "img":
                fileBasePath = String.Format("{0}/res/images", extjsBasePath);
                filePath     = String.Format("{0}/{1}", fileBasePath, typeValue);
                break;
            }

            string imageType      = GetImageFormat(typeValue);
            string filePathServer = context.Server.MapPath(filePath);

            // 非法图片后缀
            if (!_allowedImageTypes.Contains(imageType))
            {
                return;
            }

            // 不是网站根目录下的文件
            string rootPath = context.Server.MapPath(fileBasePath);

            if (!filePathServer.StartsWith(rootPath))
            {
                return;
            }

            // 不存在此文件
            if (!File.Exists(filePathServer))
            {
                return;
            }

            context.Response.WriteFile(filePathServer);
            context.Response.ContentType = "image/" + imageType;

            // 缓存一年,只能通过改变 URL 来强制更新缓存
            context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
        }
コード例 #4
0
ファイル: ResourceHandler.cs プロジェクト: 15831944/C-12-
        /// <summary>
        /// 处理资源的请求
        /// </summary>
        /// <param name="context">Http请求上下文</param>
        public void ProcessRequest(HttpContext context)
        {
            string type          = String.Empty;
            string typeValue     = String.Empty;
            string extjsBasePath = GlobalConfig.GetExtjsBasePath();

            //resName = "FineUI.";


            if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["icon"]))
            {
                type = "icon";
            }
            //else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["js"]))
            //{
            //    type = "js";
            //    //resName += "js." + typeValue;
            //}
            //else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["lang"]))
            //{
            //    type = "lang";
            //    //resName += "js.lang." + typeValue;
            //}
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["theme"]))
            {
                // res.axd?theme=default.grid.refresh.gif
                type = "theme";
                //resName += "res.theme." + typeValue;
            }
            //else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["css"]))
            //{
            //    type = "css";
            //    //resName += "res.css." + typeValue;
            //}
            else if (!String.IsNullOrEmpty(typeValue = context.Request.QueryString["img"]))
            {
                type = "img";
                //resName += "res.img." + typeValue;
            }
            else
            {
                context.Response.Write("Not supported!");
                return;
            }

            //byte[] binary;
            switch (type)
            {
            case "icon":
                if (!typeValue.EndsWith(".png") && !typeValue.EndsWith(".gif"))
                {
                    typeValue = IconHelper.GetName((Icon)Enum.Parse(typeof(Icon), typeValue));
                }
                //resName += "res.icon." + typeValue;
                string serverPath = String.Format("{0}/{1}", GlobalConfig.GetIconBasePath(), typeValue);
                context.Response.WriteFile(context.Server.MapPath(serverPath));

                context.Response.ContentType = "image/" + GetImageFormat(typeValue);
                break;

            //case "js":
            //    context.Response.Write(ResourceHelper.GetResourceContent(resName));
            //    context.Response.ContentType = "text/javascript";
            //case "lang":
            //    context.Response.Write(ResourceHelper.GetResourceContent(resName));
            //    context.Response.ContentType = "text/javascript";
            //    break;
            //case "css":
            //    context.Response.Write(ResourceHelper.GetResourceContent(resName));
            //    context.Response.ContentType = "text/css";
            //    break;
            case "theme":
                string themePath        = "";
                string themeImageFormat = "";
                int    lastDotIndex     = typeValue.LastIndexOf(".");
                if (lastDotIndex >= 0)
                {
                    themePath        = typeValue.Substring(0, lastDotIndex).Replace('.', '/');
                    themeImageFormat = typeValue.Substring(lastDotIndex + 1);
                }

                context.Response.WriteFile(context.Server.MapPath(String.Format("{0}/res/images/{1}.{2}", extjsBasePath, themePath, themeImageFormat)));

                context.Response.ContentType = "image/" + GetImageFormat(typeValue);
                break;

            case "img":
                //binary = ResourceHelper.GetResourceContentAsBinary(resName);
                //context.Response.OutputStream.Write(binary, 0, binary.Length);
                //context.Response.ContentType = "image/" + GetImageFormat(resName);


                context.Response.WriteFile(context.Server.MapPath(String.Format("{0}/res/images/{1}", extjsBasePath, typeValue)));

                context.Response.ContentType = "image/" + GetImageFormat(typeValue);
                break;
            }


            // 缓存一年,只能通过改变 URL 来强制更新缓存
            context.Response.Cache.SetExpires(DateTime.Now.AddYears(1));
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
        }