/// <summary> /// 从缓存中读取一个图片对象 /// </summary> /// <param name="RelativePath">图片相对路径</param> /// <param name="ImageDataPath">图片Txt文本路径</param> /// <returns></returns> public static FBImageInfo GetFBImageInfo(string RelativePath, string ImageDataPath) { List <FBImageInfo> cache = CacheHelper.Get <List <FBImageInfo> >("keyimagelist"); if (cache == null) { CacheHelper.Insert("keyimagelist", FBCommon.LoadFBImage(ImageDataPath)); cache = CacheHelper.Get <List <FBImageInfo> >("keyimagelist"); } return(cache.Find(x => x.RelativePath == RelativePath)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string action = "myAction"; action = context.Request.Form["myaction"]; string imageid = context.Request.Form["imageid"]; switch (action) { case "login": string password = context.Request.Form["mypassword"].ToString(); if (password == ConfigHelper.Password) { context.Session["password"] = ConfigHelper.Password; context.Response.Write("<script>window.location = '/FBImageView.ashx';</script>"); } break; case "delete": if (context.Session["password"] != null) { if (context.Session["password"].ToString() == ConfigHelper.Password) { FBCommon.DeleteImage(imageid); } } break; case "save": if (context.Session["password"] != null) { if (context.Session["password"].ToString() == ConfigHelper.Password) { string skipurl = context.Request.Form["skipurl"].Replace("|", ""); string title = context.Request.Form["title"].Replace("|", ""); string alt = context.Request.Form["alt"].Replace("|", ""); FBCommon.SaveImage(imageid, skipurl, title, alt); } } break; default: context.Response.Write("Hello World"); break; } }
public static void RefreshCache(string imagedatapath) { List <FBImageInfo> cache = CacheHelper.Get <List <FBImageInfo> >("keyimagelist"); if (cache == null) { CacheHelper.Insert("keyimagelist", FBCommon.LoadFBImage(imagedatapath)); cache = CacheHelper.Get <List <FBImageInfo> >("keyimagelist"); } else { cache.Clear(); CacheHelper.Insert("keyimagelist", FBCommon.LoadFBImage(imagedatapath)); cache = CacheHelper.Get <List <FBImageInfo> >("keyimagelist"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; //图片数据库 string imageDataPath = context.Server.MapPath("~/imagedata.txt"); //上传文件集合 HttpFileCollection fileColl = context.Request.Files; if (fileColl != null && fileColl.Count > 0) { HttpPostedFile file = fileColl[0]; string fileName = file.FileName; string fileExt = Path.GetExtension(fileName); fileName = VTS.Common.VTSCommon.GetOrderNumber() + fileExt; string filePath = context.Server.MapPath("/imageslib/" + fileName); if (System.IO.File.Exists(filePath)) { context.Response.Write("<a href='javascript:window.history.go(-1)'>返回</a><br />"); context.Response.Write("已存在同名的图片,请重命名之后再上传!<br />"); } else { file.SaveAs(filePath); //存储参数:图片ID,图片名字,图片相对路径,跳转URL,图片title,图片alt FBCommon.WriteLine(imageDataPath, string.Concat(DateTime.Now.Ticks, "|", fileName, "|", "/imageslib/" + fileName, "|", "skipurl", "|", "title", "|", "alt")); context.Response.Write("上传成功!<br />"); context.Response.Write("查看图片-><a href='/FBImageView.ashx'>查看图片</a>"); } /* * long ticks = DateTime.Now.Ticks; * DateTime now = new DateTime(ticks); * context.Response.Write(now.ToString("yyyy-MM-dd hh:mm:ss")); */ } else { context.Response.Write("上传失败!"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string template = context.Server.MapPath("/Template"); string imageDataPath = context.Server.MapPath("~/imagedata.txt"); VelocityHelper helper = new VelocityHelper(template); if (context.Session["password"] != null) { if (context.Session["password"].ToString() == ConfigHelper.Password) { List <FBImageInfo> ls = FBCommon.LoadFBImage(imageDataPath); helper.PutSet("imagelist", ls); helper.Display("imageview.html"); } } else { helper.Display("password.html"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request.QueryString == null ? "" : context.Request.QueryString["action"].ToString(); switch (action) { case "refreshcache": //刷新缓存 string imageDataPath = ConfigHelper.BaseDirectory + "imagedata.txt"; FBCommon.RefreshCache(imageDataPath); context.Response.Write("缓存刷新成功!"); break; case "reboot": HttpRuntime.UnloadAppDomain(); context.Response.Write("退出成功!"); break; default: context.Response.Write("Hello World!"); break; } }
static ConfigHelper() { _baseDirectory = AppDomain.CurrentDomain.BaseDirectory; _password = FBCommon.GetPassword(); }
public void ProcessRequest(HttpContext Context) { #region 阻止缓存 Context.Response.Clear(); Context.Response.ClearHeaders(); Context.Response.ClearContent(); Context.Response.ContentType = "text/html"; //页面后退刷新的关键 Context.Response.Cache.SetCacheability(HttpCacheability.NoCache); Context.Response.Cache.SetNoStore(); #endregion #region 定义变量 //请求文件 /imageslib/a.jpg string imagefile = Context.Request.Path; #endregion #region 跳转判断 //来源判断 Uri url = Context.Request.UrlReferrer; if (url != null) { string refurl = url.ToString().ToLower(); if (!string.IsNullOrEmpty(refurl)) { LogOut.Info("UrlReferrer:" + refurl); if (refurl.Contains("facebook.com")) { //获取图片 FBImageInfo image = FBCommon.GetFBImageInfo(imagefile, imageDataPath); if (image != null) { if (image.ImageSkipUrl != "skipurl") { #region 记录日志 LogOut.Info(("Images:" + imagefile).PadRight(100) + "," + url.ToString()); #endregion #region 301 跳转 //301跳转方式 Utils.SetURL301(Context, image.ImageSkipUrl); #endregion #region 脚本跳转 //响应脚本跳转 //Context.Response.ContentType = "application/x-javascript"; //Context.Response.ContentType = "text/html"; //Context.Response.Write(Common.ReadTextToendByUTF8(js)); //VTSCommon.TraceLog("图片:" + imagefile + "," + url.ToString(), logPath, true, null); //Context.Response.End(); #endregion } } } } } #endregion #region 展示图片 string filePath = Context.Server.MapPath(imagefile);//Context.Request.PhysicalPath; if (File.Exists(filePath)) { InitContentType(Context, filePath); int Length; Context.Response.OutputStream.Write(CacheImage(filePath, out Length), 0, Length); } else { Context.Response.ContentType = "text/html"; Context.Response.Write("No found!"); } #endregion }