论坛风格切换切换到宽版
  • 3697阅读
  • 1回复

ASP程序中网站地图生成代码 [复制链接]

上一主题 下一主题
离线天各一方
 

发帖
1374
铜币
11498
威望
505
只看楼主 倒序阅读 使用道具 楼主  发表于: 2012-07-18
为了方便访客访问,很多网站都有一个网站地图,下面的代码可以帮你轻松生成你的网站地图。
将下面的代码保存为sitemap.asp,然后放到网站根目录下,设定要生成的文件夹名字,运行,就OK了。
  1. <%
  2. ' sitemap.asp
  3. session("count")=0
  4. '你的域名
  5. session("server")="http://你的网站地址"
  6. '制作生成SiteMap.xml的目录,后面不要带"/",大小写敏感
  7. vDir = "/XXXXX"
  8. '设置你想要GOOGLE收录的文件文件名扩展名
  9. Extensions = Array("png","gif","jpg","jpeg","zip","pdf","ps","html","htm","asp","php","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","swf","wks","wps","wdb","wri","rtf","ans","txt","shtml","shtm")
  10. '需要过滤的目录
  11. PathExclusion=Array("\admin","\_vti_cnf","_vti_pvt","_vti_log","cgi-bin","aspnet_client")
  12. set objfso = CreateObject("Scripting.FileSystemObject")
  13. root = Server.MapPath(vDir)
  14. 'response.End
  15. '创建文件
  16. objfso.createtextfile(server.mappath("/sitemap.xml"))
  17. response.write "<p><strong style='font-family:arial,sans-serif;font-size=12'>创建SiteMap.xml成功!</strong><I style='font-family:arial,sans-serif;font-size=12'> "&server.mappath("/sitemap.xml")&" </I></p>"
  18. response.write "<p><strong style='font-family:arial,sans-serif;font-size=12'>正在索引文件,请稍侯...</strong></p>"
  19. Set openfileobj=objfso.opentextfile(server.mappath("/sitemap.xml"),8)
  20. openfileobj.writeline"<?xml version='1.0' encoding='UTF-8'?>"
  21. openfileobj.writeline"<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>"
  22. Set objFolder = objFSO.GetFolder(root)
  23. Set colFiles = objFolder.Files
  24. For Each objFile In colFiles
  25. openfileobj.writeline getfilelink(objFile.Path,objfile.dateLastModified)
  26. Next
  27. ShowSubFolders(objFolder)
  28. openfileobj.writeline "</urlset>"
  29. response.write "<p><strong style='font-family:arial,sans-serif;font-size=12'>SiteMap.xml生成完毕,共<span style=color:#FF0000> "&session("count")&" </span>个文件被索引</strong></p>"
  30. set fso = nothing
  31. Sub ShowSubFolders(objFolder)
  32. Set colFolders = objFolder.SubFolders
  33. For Each objSubFolder In colFolders
  34. if folderpermission(objSubFolder.Path) then
  35. openfileobj.writeline getfilelink(objSubFolder.Path,objSubFolder.dateLastModified)
  36. Set colFiles = objSubFolder.Files
  37. For Each objFile In colFiles
  38. openfileobj.writeline getfilelink(objFile.Path,objFile.dateLastModified)
  39. Next
  40. ShowSubFolders(objSubFolder)
  41. end if
  42. Next
  43. End Sub
  44. Function getfilelink(file,datafile)
  45. file=replace(file,root,"")
  46. file=replace(file,"\","/")
  47. If FileExtensionIsBad(file) then Exit Function
  48. if month(datafile)<10 then filedatem="0"
  49. if day(datafile)<10 then filedated="0"
  50. filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
  51. getfilelink = "<url>"&Chr("10")&"<loc>"&server.htmlencode(session("server")&vDir&file)&"</loc>"&Chr("10")&"<lastmod>"&filedate&"</lastmod>"&Chr("10")&"<changefreq>daily</changefreq>"&Chr("10")&"<priority>1.0</priority>"&Chr("10")&"</url>"
  52. session("count")=session("count")+"1"
  53. Response.Flush
  54. End Function
  55. Function Folderpermission(pathName)
  56. Folderpermission =True
  57. for each PathExcluded in PathExclusion
  58. if instr(ucase(pathName),ucase(PathExcluded))>0 then
  59. Folderpermission = False
  60. exit for
  61. end if
  62. next
  63. End Function
  64. Function FileExtensionIsBad(sFileName)
  65. Dim sFileExtension, bFileExtensionIsValid, sFileExt
  66. if len(trim(sFileName)) = 0 then
  67. FileExtensionIsBad = true
  68. Exit Function
  69. end if
  70. sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
  71. bFileExtensionIsValid = false
  72. for each sFileExt in extensions
  73. if ucase(sFileExt) = ucase(sFileExtension) then
  74. bFileExtensionIsValid = True
  75. exit for
  76. end if
  77. next
  78. FileExtensionIsBad = not bFileExtensionIsValid
  79. End Function
  80. %>
离线yycadmin

发帖
1995
铜币
22151
威望
509
只看该作者 沙发  发表于: 2012-12-30
这个太好了
快速回复
限100 字节
批量上传需要先选择文件,再选择上传
 
上一个 下一个