Exemplo n.º 1
0
        private string GetFilePath(string rawUrl)
        {
            string       filePath = rawUrl;
            Confighelper config   = new Confighelper();

            foreach (string item in config.ImageStyleList)
            {
                if (rawUrl.EndsWith("_" + item))
                {
                    filePath = rawUrl.Replace("_" + item, "");
                }
            }
            return(filePath);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ImageStyle"></param>
        /// <returns></returns>
        private bool IsImageStyle(string ImageStyle)
        {
            bool         b      = false;
            Confighelper config = new Confighelper();

            b = config.ImageStyleList.Contains(ImageStyle);
            //if (ImageStyle == "w100.jpg"
            //    || ImageStyle == "w200.jpg"
            //    || ImageStyle == "w300.jpg"
            //    || ImageStyle == "w400.jpg"
            //    || ImageStyle == "w500.jpg"
            //    || ImageStyle == "w600.jpg"
            //    || ImageStyle == "w700.jpg"
            //    || ImageStyle == "w800.jpg")
            //{
            //    b = true;
            //}
            return(b);
        }
Exemplo n.º 3
0
        private void OnBeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;

            try
            {
                //CurrentExecutionFilePath 不会带有 ?后面的, RawUrl 带有?t=1
                string requestUrl = app.Request.CurrentExecutionFilePath;
                string path       = requestUrl;//upload/10004/Picture/2017_07_05/20170305100315_66580.jpg_w400.jpg
                if (!string.IsNullOrEmpty(path) && path.Length > 1)
                {
                    Confighelper config = new Confighelper();
                    if (path.Contains(config.OrigDirectory))
                    {
                        //正则匹配格式
                        //http://img.cms.com/upload/10004/Picture/2017_07_05/20170305100315_66580.jpg_w400.jpg
                        if (!ImgRewriteUrl(app, path))
                        {
                            app.Response.StatusCode = 404;
                            app.Response.Write(Get404Html());
                        }
                    }
                    else
                    {
                        app.Response.StatusCode = 404;
                        app.Response.Write(Get404Html());
                    }
                }
                else
                {
                    app.Response.StatusCode = 404;
                    app.Response.Write(Get404Html());
                }
            }
            catch (Exception ex)
            {
                app.Response.StatusCode = 404;
                app.Response.Write(Get404Html());
            }
        }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            Response = context.Response;
            try
            {
                int    width     = Convert.ToInt32(context.Request["width"]); //宽度
                string filePath  = context.Request["path"];                   //相对路径 原图/upload/10004/Picture/2017_07_05//图1.jpg
                string orig_Path = context.Server.MapPath(filePath);          //原图绝对地址 C://项目1/upload/10004/Picture/2017_07_05//图1.jpg
                #region 原图

                if (System.IO.File.Exists(orig_Path))
                {
                    if (width == 0)//原图
                    {
                        ResponseBinaryWrite(orig_Path);
                    }
                    else
                    {
                        //缩图换一个位置 方便清理
                        Confighelper config = new Confighelper();

                        //context.Server.MapPath一定在注意 如果是虚拟目录 C://项目2/upload/10004/Picture/2017_07_05//图1.jpg
                        string path      = context.Server.MapPath(filePath.Replace(config.OrigDirectory, config.TempDirectory));
                        string tnImgPath = path + context.Request["ImageStyle"];
                        //创建文件夹
                        string dir = System.IO.Path.GetDirectoryName(tnImgPath);
                        if (!System.IO.Directory.Exists(dir))
                        {
                            System.IO.Directory.CreateDirectory(dir);
                        }
                        if (System.IO.File.Exists(tnImgPath))
                        {
                            ResponseBinaryWrite(tnImgPath);
                        }
                        else
                        {
                            #region  存在则 进行动态缩图
                            Image  origImage = Image.FromFile(orig_Path);
                            Bitmap Tn_imgsrc = ImageHelper.GetThumbnailImage(origImage, ThumbnailImageType.Zoom, width, 0);
                            if (config.IsRealGenerate == 1)
                            {
                                Tn_imgsrc.Save(tnImgPath);
                            }
                            origImage.Dispose();
                            ResponseBinaryWrite(tnImgPath);
                            #endregion
                        }
                    }
                }
                else
                {
                    Response.StatusCode = 404;
                    Response.Write(Get404Html());
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogCommon.Logs.LogError(ex.ToString());
                Response.StatusCode = 404;
                Response.Write(Get404Html());
            }
        }