Subject: Using the FileSystemObject
Posted By: malhyp Post Date: 10/2/2005 1:52:15 AM
Heya all. Can anyone see what I have done wrong.

I have created a txt file with a password. Also inserted all the code in the login.asp file.

Every time I test the for I get default 'The page cannot be displayed'

The code is right out of the book. Just cant understand where I have gone wrong.

Code here:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Dim sErrorMessage
Dim sReferrer
If Request.Form("txtReferrer") = "" Then
sReferrer = Request.QueryString("accessdenied")
Else
sReferrer = Request.Form("txtReferrer")
End If
If sReferrer = "" Then
sReferrer = "search.asp"
End If
If Request.Form("txtUserName") <> "" And _
Request.Form("txtPassword") <> "" Then
Const ForReading = 1
Dim oFileSystemObject
Dim oTextStream
Dim sFileLocation
Dim sTempString
Dim arrTemp
Dim bUserFound
If Request.Form("btnLogin") <> "" Then
sFileLocation = Server.MapPath("Tools/users.txt")
        
' Create an instance of the FileSystemObject
Set oFileSystemObject = Server.CreateObject("Scripting.FileSystemObject")
        
' Create a reference to our text file so we can read from it
Set oTextStream = oFileSystemObject.OpenTextFile(sFileLocation, ForReading)
        
' Read in each line until we reach the end of the file
Do While (Not oTextStream.AtEndOfStream = True)
' Read a line
sTempString = oTextStream.ReadLine()
            
' If the line contains text
If Len(sTempString) > 0 Then
' The line should hold the username and password, separated by a tab
' Split the line based on a tab, so we get the username and password
' in two separate array elements
arrTemp = Split(sTempString, vbTab)
        
If IsArray(arrTemp) Then
' An UBound of 1 means two elements in the array, the username
' and the password. If we haven't found both, we do not continue
            
If UBound(arrTemp) = 1 Then
' Compare array elements with username and password
        
If arrTemp(0) = Request.Form("txtUserName") And _
arrTemp(1) = Request.Form("txtPassword") Then
bUserFound = True
Exit Do
End If
End If
End If
End If
Loop
' Close our textstream and clean up our objects
oTextStream.Close
Set oTextStream = Nothing
Set oFileSystemObject = Nothing
        
If bUserFound = True Then
Session("MM_Username") = Request.Form("txtUserName")
Response.Redirect(sReferrer)
Else
sErrorMessage = "<span class=""clsErrorMessage""><br>" & _
"Login failed. Please type a valid username and password</span>"
End If
End If
End If
%>

TA
Mal.


Reply By: Imar Reply Date: 10/2/2005 7:00:39 AM
Do you have software like Norton Internet Security / Anti Virus or McAfee anti-virus?

These applications have a "script blocking" feature that prevent your ASP pages from using the FSO.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.

Go to topic 35303

Return to index page 461
Return to index page 460
Return to index page 459
Return to index page 458
Return to index page 457
Return to index page 456
Return to index page 455
Return to index page 454
Return to index page 453
Return to index page 452