//防止恶意请求 public static bool IsRedis(HttpContext context) { if (context.Request.Browser.Crawler) { return(false); } string key = userIP; bool check = RedisCacheTools.Exists(key); if (check) { RedisCacheTools.Incr(key); int hit = RedisCacheTools.Get <int>(key); if (hit > 5) { return(false); } /* * $redis->incr($key); * $count = $redis->get($key); * if($count > 5){ * exit('请求太频繁,请稍后再试!'); * } */ } else { DateTime dt = DateTime.Now.AddDays(1); RedisCacheTools.Incr(key); /* * $redis->incr($key); * //限制时间为60秒 * $redis->expire($key,60) */ RedisCacheTools.Expire(key, dt); } return(true); }
private string gotoRedirectUrl = "/404.html";//最终用户访问的网址 public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string jump = QueryString("jump"); //参数1:用户传当前推广的网址 string getJump = jump; //参数1:用户传当前推广的网址 if (string.IsNullOrEmpty(getJump)) { context.Response.Redirect(gotoRedirectUrl); } else { Random ran = new Random(); int RandKey = ran.Next(00, 99); getJump = getJump + "!" + RandKey; string domainLeft = "https://"; string isHttps = ConfigTool.ReadVerifyConfig("IsSSL", "WapToWeiXin"); if (isHttps.ToLower() == "false") { domainLeft = "http://"; } string domainCenter = GetRandHostUrl(); gotoRedirectUrl = domainLeft + domainCenter + "/HomeWX.aspx"; string html = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "dev/sply.html"); html = html.Replace("$newsView", gotoRedirectUrl).Replace("$newsValue", getJump); bool check = RedisCacheTools.Exists(jump + "IsTitle"); if (check) { html = html.Replace("太阳湾软件", ""); } context.Response.Write(html); } context.Response.End(); }