防盗代码

Uri u = context.Request.UrlReferrer;//访问来源地址
string ip = context.Request.UserHostAddress;//访问来源IP
string serverHost = context.Request.Url.Host;//当前访问主机地址
            
string localIP=System.Configuration.ConfigurationManager.AppSettings["LocalIP"];
if (u == null || u.Host.ToLower() != serverHost.ToLower() || ip != localIP)
{
     context.Response.Write("非本地访问");
}
else
{
     context.Response.WriteFile(context.Request.PhysicalPath);
}

 

posted @ 2012-12-11 21:18  一千零一夜  阅读(248)  评论(0编辑  收藏  举报