asp实现禁止搜索引擎蜘蛛访问的代码

ASP教程 2025-07-30

这篇文章主要介绍了asp实现禁止搜索引擎蜘蛛访问的代码,十分的简单实用,有需要的小伙伴可以参考下。

这段代码可以控制常用的搜索引擎无法访问asp页面,需要在每个asp页面包含这段代码。

  1. <%
  2. functionisspider()
  3. dimi,agent,searray
  4. agent=agent:&LCase(request.servervariables(http_user_agent))
  5. searray=array(googlebot,baiduspider,sogouspider,yahoo,Sosospider)
  6. isspider=false
  7. fori=0toubound(searray)
  8. if(instr(agent,searray(i))>0)thenisspider=true
  9. next
  10. endfunction
  11. functionfromse()
  12. dimurlrefer,searray,i
  13. urlrefer=refer:&LCase(request.ServerVariables(HTTP_REFERER))
  14. fromse=false
  15. ifurlrefer=thenfromse=false
  16. searray=array(google,baidu,sogou,yahoo,soso)
  17. fori=0toubound(searray)
  18. if(instr(urlrefer,searray(i))>0)thenfromse=true
  19. next
  20. endfunction
  21. if(isspider())then
  22. dimmyfso,fileurl,filecon,myfile
  23. fileurl=Server.MapPath(images/bg01.gif)
  24. Setmyfso=Server.CreateObject(Scripting.FileSystemObject)
  25. ifmyfso.FileExists(fileurl)then
  26. Setmyfile=myfso.OpenTextFile(fileurl,1)
  27. filecon=myfile.readAll
  28. response.write(filecon)
  29. myfile.Close
  30. Setmyfile=Nothing
  31. Setmyfso=Nothing
  32. response.end
  33. endif
  34. endif
  35. if(fromse())then
  36. response.write(
    )
  37. response.end
  38. else
  39. endif
  40. %>

以上所述就是本文的全部内容了,希望大家能够喜欢。