I am learning ASP whilst building a website to allow users to login and edit text files which are part of ofther websites i make for them. I have 3 pages: index.asp which is a simple login form with code for checking if username and password is correct. This creates a session object which stores the username and a string "YES" if the password is valid and "NO" if not. This all works perfectly. The second page is a page to edit the text file. It reads the seession object and then displays the text contained in the text file. It will also display a form for enterning new text into the file. Every user will have a different folder on the server named identically to their username. So for example, username "umb01" will have a folder called "umb01" containg a file called news.txt. This page also works fine, except when u click on the submit button on the form. It takes you to the page upload_news.asp which is where the problems come in. This page should simply write the data to the file but it return an error.Heres the codeindex.asp:
<html><head><%sub refresh() dim fname, password, usrdata(2), pswrddata(2), i, j fname=Request.form("fname") password=Request.form("pswrd") If fname<>"" Then usrdata(0)="umb01" usrdata(1)="umb02" usrdata(2)="umb03" pswrddata(0) ="cheese" pswrddata(1) ="beef" pswrddata(2) = "pedo" j=200 for i = 0 to 2 If usrdata(i) = fname Then j = i response.write("Usr names match, checking passwords <br/>") End If next If j<=199 Then If password=pswrddata(j) Then response.write("passwords match <br/> Access Granted") Session("permission")="YES" Session("username")=fname Response.Redirect("ftp.asp") Response.End() Else response.write("Access Denied") Session("permission")="NO" Session("username")=fname Response.Redirect("ftp.asp") Response.End() End If End If End Ifend sub%><body><form action="index.asp" method="post">Your name: <input type="text" name="fname" size="20" />Your pswrd: <input type="password" name="pswrd" size="20" /><input type="submit" value="Submit" /></form><%call refresh()%></body></html>
ftp.asp:
<html> <title>Our private pages</title> <body><%If Session("permission") = "YES" Then Response.write("Access Granted")%> Current Text:<br> <% Dim fs,f, usr, newsTxt, ts, fo usr = Session("username") newsTxt = request.form("news") Set fs=Server.CreateObject("Scripting.FileSystemObject") Set f=fs.OpenTextFile(Server.MapPath(usr & "\news.txt"), 1) Response.write(f.ReadAll) set f=nothing set fs=nothing %> <FORM ACTION="upload_news.asp" METHOD=post> News: <input type="textarea" name="news" size="20" /> <INPUT TYPE=submit value="Submit"> </FORM>)<% Else Response.write("Access Denied")End If%></body> </html>
upload_news.asp:
<html> <title>Edit News Page</title> <body><%Dim fs,f, usr, newsTxtusr = Session("username")newsTxt = request.form("news")Set fs=Server.CreateObject("Scripting.FileSystemObject")Set f = fs.CreateTextFile(Server.MapPath(usr & "\news.txt"))f.write(newsTxt)set f=nothingset fs=nothing%></body> </html>
The problem line seams to be this one:Set f = fs.CreateTextFile(Server.MapPath(usr & "\news.txt"))but i don't know what ive done wrong.If anyone has any suggestions / comments / ideas, please help! I am running windows vista, so thats... IIS 7.0 i think.Thank you all.Ewen