C# asp.net简单局部防盗链,域名授权法实现
/// <summary>
/// 防盗链(授权域名法,未授权的域名将禁止访问)直接在Page_load里调用checkdomain()方法即可
/// </summary>
private void checkdomain()
{
try
{
string domain = Request.UrlReferrer.Host.ToString().ToLower();
string AuthorizeUrl = "localhost,www.a.com,www.b.com,www.c.com";//授权域名,未授权的域名将禁止访问
string[] strArray = AuthorizeUrl.Split(',');
if (Array.IndexOf(strArray, domain)>-1)
{
return;
}
else
{
Response.Write("未授权域名,禁止访问!");
Response.End();
}
}
catch (Exception)
{ return; }
}










