Using System; using System. collections. generic; using System. text; using System. web; using System. xml; using System. IO; using System. net; using System. text. regularExpressions; using extensions; namespace NetOpen_System.Component {public sealed class WebsiteSkipHttpModule: IHttpModule {# region IHttpModule member public void Dispose () {} public void Init (HttpApplication context) {context. B EginRequest + = new EventHandler (context_BeginRequest);} # endregion void context_BeginRequest (object sender, EventArgs e) {try {// if (HttpContext. current. request. isLocal) // ignore local computer requests // return; // string ip = HttpContext. current. request. userHostAddress; // string ip = HttpContext. current. request. serverVariables ["REMOTE_ADDR"]. toString (); string ip = string. empty; if (HttpContext. current. request. ser VerVariables ["HTTP_X_REAL_IP"]! = Null) {ip = HttpContext. Current. Request. ServerVariables ["HTTP_X_REAL_IP"]. ToString ();} else if (HttpContext. Current. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]! = Null) {ip = HttpContext. Current. Request. ServerVariables ["HTTP_X_FORWARDED_FOR"]. ToString ();} else if (HttpContext. Current. Request. ServerVariables ["HTTP_VIA"]! = Null) {ip = HttpContext. current. request. serverVariables ["HTTP_X_FORWARDED_FOR"]. toString ();} else {ip = HttpContext. current. request. serverVariables ["REMOTE_ADDR"]. toString ();} QQWryLocator qqWry = new QQWryLocator (HttpContext. current. server. mapPath (@"~ \ IpData \ qqwry. dat "); IPLocation ipaddress = qqWry. query (ip); // Query an ip address string ls_city = ipaddress. country; string ls_urlfrom = string. empty; string ls_urlto = string. empty; string ls_url = HttpContext. current. request. url. absoluteUri; string ls_useragentkeyword = string. empty; ExcludeUserAgentMatchEngine Em = WebsiteSkipConfiguration. getConfig (). excludeUserAgents; if (Em. excludeUserAgentList. count> 0) {foreach (ExcludeUserAgent ua in Em. excludeUserAgentList) {if (HttpContext. current. request. userAgent. contains (ua. keyword) {return ;}} UrlMatchEngine pu = WebsiteSkipConfiguration. getConfig (). skipedUrls; if (pu. urlList. count> 0) {foreach (SkipedUrl sk in pu. urlList) {if (ls_city.Contains (sk. ipCity) {if (sk. urlFrom. length> 0) {if (sk. urlFrom. contains (ls_url )&&! Ls_url.Contains (sk. outKeyWord) {if (sk. urlTo. length> 0) {HttpContext. current. response. redirect (sk. urlTo, true) ;}break ;}} break ;}}} if (WebsiteSkipConfiguration. getConfig (). ipChecks. getIpIn (ip) {ls_urlfrom = WebsiteSkipConfiguration. getConfig (). ipChecks. urlFrom. trim (); ls_urlto = WebsiteSkipConfiguration. getConfig (). ipChecks. urlTo. trim (); if (ls_urlfrom.Length> 0) {if (ls_urlfrom.Cont Ains (ls_url )&&! Ls_url.Contains (WebsiteSkipConfiguration. getConfig (). ipChecks. outKeyWord) {if (ls_urlto.Length> 0) {HttpContext. current. response. redirect (ls_urlto, true) ;}}}} catch {}}}}
SharePoint Business Intelligence Technology QQ group: 140668362,. Net technology exchange QQ group: 195516928, welcome to join the exchange. |