home *** CD-ROM | disk | FTP | other *** search
/ lib.nur.ac.rw / lib.nur.ac.rw.tar / lib.nur.ac.rw / global.asa < prev    next >
Text File  |  2008-07-16  |  3KB  |  83 lines

  1. <SCRIPT LANGUAGE=VBScript RUNAT=Server>
  2. Sub Application_OnStart
  3.     '==FrontPage Generated - startspan==
  4.     Dim FrontPage_UrlVars(0)
  5.     '--
  6.     Application("FrontPage_UrlVars") = FrontPage_UrlVars
  7.     '==FrontPage Generated - endspan==
  8. End Sub
  9. Sub Session_OnStart
  10.     FrontPage_StartSession '==FrontPage Generated==
  11. End Sub
  12. Sub FrontPage_StartSession
  13.     On Error Resume Next
  14.     if Len(Application("FrontPage_VRoot")) > 0 then Exit Sub
  15.     ' discover the VRoot for the current page;
  16.     ' walk back up VPath until we find global.asa
  17.     Vroot = Request.ServerVariables("PATH_INFO")
  18.     strG1 = "global.asa"
  19.     strG2 = "Global.asa"
  20.     iCount = 0
  21.     do while Len(Vroot) > 1
  22.         idx = InStrRev(Vroot, "/")
  23.         if idx > 0 then
  24.             Vroot = Left(Vroot,idx)
  25.         else
  26.             ' error; assume root web
  27.             Vroot = "/"
  28.         end if
  29.         if FrontPage_FileExists(Server.MapPath(Vroot & strG1)) then exit do
  30.         if FrontPage_FileExists(Server.MapPath(Vroot & strG2)) then exit do
  31.         if Right(Vroot,1) = "/" then Vroot = Left(Vroot,Len(Vroot)-1)
  32.         iCount = iCount + 1
  33.         if iCount > 100 then
  34.             ' error; assume root web
  35.             Vroot = "/"
  36.             exit do
  37.         end if
  38.     loop
  39.     ' map all URL= attributes in _ConnectionString variables
  40.     Application.Lock
  41.     if Len(Application("FrontPage_VRoot")) = 0 then
  42.         Application("FrontPage_VRoot") = Vroot
  43.         UrlVarArray = Application("FrontPage_UrlVars")
  44.         for i = 0 to UBound(UrlVarArray)
  45.             if Len(UrlVarArray(i)) > 0 then FrontPage_MapUrl(UrlVarArray(i))
  46.         next
  47.     end if
  48.     Application.Unlock
  49. End Sub
  50. Sub FrontPage_MapUrl(AppVarName)
  51.     ' convert URL attribute in conn string to absolute file location
  52.     strVal = Application(AppVarName)
  53.     strKey = "URL="
  54.     idxStart = InStr(strVal, strKey)
  55.     If idxStart = 0 Then Exit Sub
  56.     strBefore = Left(strVal, idxStart - 1)
  57.     idxStart = idxStart + Len(strKey)
  58.     idxEnd = InStr(idxStart, strVal, ";")
  59.     If idxEnd = 0 Then
  60.         strAfter = ""
  61.         strURL = Mid(strVal, idxStart)
  62.     Else
  63.         strAfter = ";" & Mid(strVal, idxEnd + 1)
  64.         strURL = Mid(strVal, idxStart, idxEnd - idxStart)
  65.     End If
  66.     strOut = strBefore & Server.MapPath(Application("FrontPage_VRoot") & strURL) & strAfter
  67.     Application(AppVarName) = strOut
  68. End Sub
  69. Function FrontPage_FileExists(fspath)
  70.     On Error Resume Next
  71.     FrontPage_FileExists = False
  72.     set fs = CreateObject("Scripting.FileSystemObject")
  73.     Err.Clear
  74.     set istream = fs.OpenTextFile(fspath)
  75.     if Err.Number = 0 then
  76.         FrontPage_FileExists = True
  77.         istream.Close
  78.     end if
  79.     set istream = Nothing
  80.     set fs = Nothing
  81. End Function
  82. </SCRIPT>
  83.