sitemap.asp
上传用户:jisenq
上传日期:2014-06-29
资源大小:7216k
文件大小:3k
源码类别:

数据库编程

开发平台:

ASP/ASPX

  1. <%
  2. Server.ScriptTimeout=50000
  3. dim seoDir
  4. kczm="http://www.3eat.cn"    '把该网址改成自己网站的
  5. seoDir="/"
  6. set objfso = CreateObject("Scripting.FileSystemObject")
  7. root = Server.MapPath(seoDir)
  8. 'response.ContentType = "text/xml"
  9. 'response.write "<?xml version='1.0' encoding='UTF-8'?>"
  10. 'response.write "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84';>"
  11. str = "<?xml version='1.0' encoding='gb2312'?>" & vbcrlf
  12. str = str & "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>" & vbcrlf
  13. Set objFolder = objFSO.GetFolder(root)
  14. 'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
  15. Set colFiles = objFolder.Files
  16. For Each objFile In colFiles
  17. str=str & getfilelink(objFile.Path,objfile.dateLastModified) & vbcrlf
  18. Next
  19. ShowSubFolders(objFolder)
  20. str = str & "</urlset>" & vbcrlf
  21. set fso = nothing
  22. Set objStream = Server.CreateObject("ADODB.Stream")
  23. With objStream
  24. .Open
  25. .Charset = "gb2312"
  26. .Position = objStream.Size
  27. .WriteText=str
  28. .SaveToFile server.mappath("/sitemap.xml"),2      '生成的XML文件名
  29. .Close
  30. End With
  31. Set objStream = Nothing
  32. If Not Err Then
  33. Response.Write("<script>alert('成功生成站点地图!');history.back();</script>")
  34. Response.End
  35. End If
  36. Sub ShowSubFolders(objFolder)
  37. Set colFolders = objFolder.SubFolders
  38. For Each objSubFolder In colFolders
  39. if folderpermission(objSubFolder.Path) then
  40. str = str & getfilelink(objSubFolder.Path,objSubFolder.dateLastModified) & vbcrlf
  41. Set colFiles = objSubFolder.Files
  42. For Each objFile In colFiles
  43. str = str & getfilelink(objFile.Path,objFile.dateLastModified) & vbcrlf
  44. Next
  45. ShowSubFolders(objSubFolder)
  46. end if
  47. Next
  48. End Sub
  49. Function getfilelink(file,datafile)
  50. file=replace(file,root,"")
  51. file=replace(file,"","/")
  52. If FileExtensionIsBad(file) then Exit Function
  53. if month(datafile)<10 then filedatem="0"
  54. if day(datafile)<10 then filedated="0"
  55. filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
  56. getfilelink = "<url><loc>"&server.htmlencode(kczm&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
  57. Response.Flush
  58. End Function
  59. Function Folderpermission(pathName)
  60. PathExclusion=Array("temp","admin")      '需要过滤的文件夹
  61. Folderpermission =True
  62. for each PathExcluded in PathExclusion
  63. if instr(ucase(pathName),ucase(PathExcluded))>0 then
  64. Folderpermission = False
  65. exit for
  66. end if
  67. next
  68. End Function
  69. Function FileExtensionIsBad(sFileName)
  70. Dim sFileExtension, bFileExtensionIsValid, sFileExt
  71. Extensions = Array("html")
  72. if len(trim(sFileName)) = 0 then
  73. FileExtensionIsBad=true
  74. Exit Function
  75. end if
  76. sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
  77. bFileExtensionIsValid=false
  78. for each sFileExt in extensions
  79. if ucase(sFileExt)=ucase(sFileExtension) then
  80. bFileExtensionIsValid=True
  81. exit for
  82. end if
  83. next
  84. FileExtensionIsBad = not bFileExtensionIsValid
  85. End Function
  86. %>