<?
XMl version="1.0" encoding="utf-8"?>
<DownLoad>
<CheckTy
PE>1</CheckType>
<CookiesN
ame>username</CookiesName>
<UrlPattern>
<![CDATA[//(.+?)/.rar/b]]>
</UrlPattern>
<UrlReplace>
<![CDATA[Default.aspx?d=$1.rar]]>
</UrlReplace>
<AllowHost>
<![CDATA[127.0.0.1]]>
</AllowHost>
</DownLoad>
void Application_Be
ginRequest(object sender, Event
args e)
{
bool IsAllowDom
ain = false;
bool Is
LOGin = false;
string CookiesName = "UserName", AllowHost, ReferrerHost="";
int CheckType = 1;
bool AllowDown = false;
string[] AllowHostArr;
string UrlPattern = "", UrlReplace = "";
string[] pattern, replace;
string
configFile = ConfigurationManager.AppSettings["DownLoadConfig"];
if (ConfigFile != "")
{
try
{
System.X
ML.XmlDataDocument XDConfig = new System.Xml.XmlDataDocument();
XDConfig.Load(AppDomain.
currentDomain.BaseDirectory + @"/" + ConfigFile);
if (XDConfig.SelectSingleNode("DownLoad/CheckType").InnerText != "")
{
CheckType = int.Parse(XDConfig.SelectSingleNode("DownLoad/CheckType").InnerText);
}
if (XDConfig.SelectSingleNode("DownLoad/CookiesName").InnerText != "")
{
CookiesName = XDConfig.SelectSingleNode("DownLoad/CookiesName").InnerText;
}
AllowHost = XDConfig.SelectSingleNode("DownLoad/AllowHost ").InnerText;
AllowHostArr = AllowHost.Split('|');
UrlPattern = XDConfig.SelectSingleNode("DownLoad/UrlPattern").InnerText;
UrlReplace = XDConfig.SelectSingleNode("DownLoad/UrlReplace").InnerText;
pattern = UrlPattern.Split('@');
replace = UrlReplace.Split('@');
if (CookiesName
== "") CookiesName = "UserName";
IsLogin = false.Equals(Request.Cookies[CookiesName] == null || Request.Cookies[CookiesName].Value == "");
if (Request.UrlReferrer != null) ReferrerHost = Request.UrlReferrer.Host.ToString();
if (AllowHostArr.Length < 1)
{
IsAllowDomain = true;
}
else
{
for (int HostI = 0; HostI < AllowHostArr.Length - 1; Host
i++)
{
if (AllowHostArr[HostI].ToLower() == ReferrerHost.ToLower())
{
IsAllowDomain = true;
break;
}
}
}
switch (CheckType)
{
case 1:
AllowDown = true.Equals(IsAllowDomain);
break;
case 2:
AllowDown = IsLogin;
break;
case 3:
AllowDown = true.Equals(IsAllowDomain
&& IsLogin);
break;
}
if (AllowDown == false)
{
string oldUrl = HttpContext.Current.Request.RawUrl;
string newUrl = oldUrl;
for (int iii = 0; iii < pattern.Length; iii++)
{
if (Regex.IsMatch(oldUrl, pattern[iii], RegexOptions.IgnoreCase | RegexOptions
.COMpiled))
{
newUrl = Regex.Replace(oldUrl, pattern[iii], replace[iii], RegexOptions.Compiled | RegexOptions.IgnoreCase);
oldUrl = newUrl;
}
}
this.Context.RewritePath(newUrl);
}
}
catch
{
}
}
}
可执行文件填入:c:/windows/microsoft.net/framework/v2.0.50727/aspnet_isapi.dll(视实际情况变动,与.aspx的一样就成)
添加了这个就等于把所有的请求都交给了.net,这样实现的防盗链,即使是迅雷或是别的什么下载工具照样是下不了的,下的文件名虽然是那个但是内容就完全不是了,嘿嘿。。。