DigitalMyth
May 28th, 2004, 06:38 AM
I can either get
Object reference not set to an instance of an object.
or
Value cannot be null. Parameter name: Argument 'Array' is Nothing.
<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Dim Directorys() as String
Dim Files as New ArrayList
Sub Page_Load
If User.Identity.ISAuthenticated = "false" then
If not Request.QueryString("act") = "login" then Response.Redirect( scriptname & "?act=login")
End if
If Request.QueryString("act") = "explore" then LoadDirs(gethome(Request.ServerVariables("AUTH_USER")))
If Request.QueryString("act") = "explore" then LoadFiles(gethome(Request.ServerVariables("AUTH_USER")))
End Sub
Function Authenticated(username As String, password As String) As Boolean
Dim dbconnection As Sqlconnection, getuserID as Sqlcommand, userID as SqlDataReader
dbconnection = New SqlConnection( "Server=;uid=commline;pwd=;database=" )
dbconnection.open()
getuserID = New sqlcommand( "Select u_basedir FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(txtuser.text) & "' AND u_password = '" & Microsoft.Visualbasic.Lcase(txtpass.text) & "'", dbconnection )
userID = getuserID.ExecuteReader()
If userID.HasRows then
While userID.Read()
Return True
End While
Else
Return False
End if
userID.close()
dbconnection.close()
End Function
Sub TryLogin(sender As Object, e As EventArgs)
If Authenticated(txtuser.text,txtpass.text) then
Dim ticket as New FormsAuthenticationTicket( txtuser.text, chkrem.checked, 50 )
Dim encTicket As String = FormsAuthentication.Encrypt(ticket)
Dim cookie as New HttpCookie(FormsAuthentication.FormsCookieName,encticket)
Response.Cookies.Add(cookie)
response.redirect(scriptname & "?act=summary")
else
Logerror.Visible = true
End if
End Sub
Function Scriptname as string
Dim strURL
Dim aryURL
strURL = Request.ServerVariables("SCRIPT_NAME")
aryURL = Split(strURL, "/", -1, 1)
scriptname = (aryURL(ubound(aryURL)))
End Function
Function LoadDirs(strcurrentdir as string)
Dim Directorys() as String
Dim i as Integer
Directorys = Directory.GetDirectories(strCurrentDir)
For i = 0 to ubound(Directorys)
Directorys(i) = right(Directorys(i), len(Directorys(i)) - len(strcurrentdir) - 1)
next i
End Function
Function LoadFiles(strCurrentDir as string)
Dim i as integer
Dim filesstore as Array
Dim runningfile as FileInfo
Dim dir as DirectoryInfo
dir = new DirectoryInfo(strCurrentDir)
filesstore = dir.GetFiles()
For each runningfile in filesstore
files.add(runningfile.name)
next
files.TrimToSize()
End Function
Function GetHome(Username as string) as string
Dim dbconnection As Sqlconnection, getuserID as Sqlcommand, userID as SqlDataReader
dbconnection = New SqlConnection( "Server=;uid=commline;pwd=;database=" )
dbconnection.open()
getuserID = New sqlcommand( "Select u_basedir FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(username) & "'", dbconnection )
userID = getuserID.ExecuteReader()
If userID.HasRows then
While userID.Read()
Return userid( "u_basedir" )
End While
End if
userID.close()
dbconnection.close()
End Function
</script>
<html>
<head>
<STYLE type=text/css>
BODY {background-image: url(img\back_logo.jpg);
background-repeat: no-repeat;
background-position: bottom right
scrollbar-3dlight-color:#f3f3f3;
scrollbar-arrow-color:#000000;
scrollbar-base-color:#cccccc;
scrollbar-track-color:#f3f3f3;
scrollbar-darkshadow-color:#f3f3f3;
scrollbar-highlight-color:#f3f3f3;
</STYLE>
</head>
<body>
<% Select Case Request.QueryString("act") %>
<% Case "login" %>
<form runat="server"><p><font face="Trebuchet MS" size="5"><strong>CLIENT LOGIN</strong></font></p><p><font size="2"><font face="Trebuchet MS">Username:</font><br /></font><asp:TextBox id="txtuser" runat="server"></asp:TextBox></p><p><font face="Trebuchet MS" size="2">Password:</font><br /><asp:TextBox id="txtpass" runat="server" TextMode="Password"></asp:TextBox></p><p><asp:CheckBox id="chkrem" runat="server" Text="Remember me with Cookies?"></asp:CheckBox><br /><br />
<aspanel id="logerror" runat="server" Visible="False" font-names="Trebuchet MS" font-size="X-Small" forecolor="Red" font-bold="True">
Your Password or Username is incorrect.
</aspanel>
</p><p><asp:Button id="login" onclick="trylogin" runat="server" Text="Login" Width="72px"></asp:Button></p></form>
<% Case "summary" %>
<p><font face="MS Sans Serif" style="font-size: 11pt"><a href="?act=explore">Explore your files in your area</a></p><br> Script: <% Response.Write(ScriptName) %> <br> Version: BETA 0.1 <br> <br> Copyright © Script: <b> <% Response.Write(ScriptName) %> </b> Andrew Simpson 2004-2005
<% Case "explore"
Dim Temp as String
Dim m as Integer %>
<% For m = 0 to ubound(Directorys)
response.write(ubound(directorys))
next m %>
<% Case Else
Response.Redirect( scriptname & "?act=login") %>
<% End Select %>
</body>
</html>
<b>Now i have a feeling that the Directorys arrays and the Files arrays are wiped when it's jumps out of the script section at the top of the file but i'm not sure. </b>
Can Anyone help??
Object reference not set to an instance of an object.
or
Value cannot be null. Parameter name: Argument 'Array' is Nothing.
<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Dim Directorys() as String
Dim Files as New ArrayList
Sub Page_Load
If User.Identity.ISAuthenticated = "false" then
If not Request.QueryString("act") = "login" then Response.Redirect( scriptname & "?act=login")
End if
If Request.QueryString("act") = "explore" then LoadDirs(gethome(Request.ServerVariables("AUTH_USER")))
If Request.QueryString("act") = "explore" then LoadFiles(gethome(Request.ServerVariables("AUTH_USER")))
End Sub
Function Authenticated(username As String, password As String) As Boolean
Dim dbconnection As Sqlconnection, getuserID as Sqlcommand, userID as SqlDataReader
dbconnection = New SqlConnection( "Server=;uid=commline;pwd=;database=" )
dbconnection.open()
getuserID = New sqlcommand( "Select u_basedir FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(txtuser.text) & "' AND u_password = '" & Microsoft.Visualbasic.Lcase(txtpass.text) & "'", dbconnection )
userID = getuserID.ExecuteReader()
If userID.HasRows then
While userID.Read()
Return True
End While
Else
Return False
End if
userID.close()
dbconnection.close()
End Function
Sub TryLogin(sender As Object, e As EventArgs)
If Authenticated(txtuser.text,txtpass.text) then
Dim ticket as New FormsAuthenticationTicket( txtuser.text, chkrem.checked, 50 )
Dim encTicket As String = FormsAuthentication.Encrypt(ticket)
Dim cookie as New HttpCookie(FormsAuthentication.FormsCookieName,encticket)
Response.Cookies.Add(cookie)
response.redirect(scriptname & "?act=summary")
else
Logerror.Visible = true
End if
End Sub
Function Scriptname as string
Dim strURL
Dim aryURL
strURL = Request.ServerVariables("SCRIPT_NAME")
aryURL = Split(strURL, "/", -1, 1)
scriptname = (aryURL(ubound(aryURL)))
End Function
Function LoadDirs(strcurrentdir as string)
Dim Directorys() as String
Dim i as Integer
Directorys = Directory.GetDirectories(strCurrentDir)
For i = 0 to ubound(Directorys)
Directorys(i) = right(Directorys(i), len(Directorys(i)) - len(strcurrentdir) - 1)
next i
End Function
Function LoadFiles(strCurrentDir as string)
Dim i as integer
Dim filesstore as Array
Dim runningfile as FileInfo
Dim dir as DirectoryInfo
dir = new DirectoryInfo(strCurrentDir)
filesstore = dir.GetFiles()
For each runningfile in filesstore
files.add(runningfile.name)
next
files.TrimToSize()
End Function
Function GetHome(Username as string) as string
Dim dbconnection As Sqlconnection, getuserID as Sqlcommand, userID as SqlDataReader
dbconnection = New SqlConnection( "Server=;uid=commline;pwd=;database=" )
dbconnection.open()
getuserID = New sqlcommand( "Select u_basedir FROM Userfile WHERE u_username = '" & Microsoft.Visualbasic.Lcase(username) & "'", dbconnection )
userID = getuserID.ExecuteReader()
If userID.HasRows then
While userID.Read()
Return userid( "u_basedir" )
End While
End if
userID.close()
dbconnection.close()
End Function
</script>
<html>
<head>
<STYLE type=text/css>
BODY {background-image: url(img\back_logo.jpg);
background-repeat: no-repeat;
background-position: bottom right
scrollbar-3dlight-color:#f3f3f3;
scrollbar-arrow-color:#000000;
scrollbar-base-color:#cccccc;
scrollbar-track-color:#f3f3f3;
scrollbar-darkshadow-color:#f3f3f3;
scrollbar-highlight-color:#f3f3f3;
</STYLE>
</head>
<body>
<% Select Case Request.QueryString("act") %>
<% Case "login" %>
<form runat="server"><p><font face="Trebuchet MS" size="5"><strong>CLIENT LOGIN</strong></font></p><p><font size="2"><font face="Trebuchet MS">Username:</font><br /></font><asp:TextBox id="txtuser" runat="server"></asp:TextBox></p><p><font face="Trebuchet MS" size="2">Password:</font><br /><asp:TextBox id="txtpass" runat="server" TextMode="Password"></asp:TextBox></p><p><asp:CheckBox id="chkrem" runat="server" Text="Remember me with Cookies?"></asp:CheckBox><br /><br />
<aspanel id="logerror" runat="server" Visible="False" font-names="Trebuchet MS" font-size="X-Small" forecolor="Red" font-bold="True">
Your Password or Username is incorrect.
</aspanel>
</p><p><asp:Button id="login" onclick="trylogin" runat="server" Text="Login" Width="72px"></asp:Button></p></form>
<% Case "summary" %>
<p><font face="MS Sans Serif" style="font-size: 11pt"><a href="?act=explore">Explore your files in your area</a></p><br> Script: <% Response.Write(ScriptName) %> <br> Version: BETA 0.1 <br> <br> Copyright © Script: <b> <% Response.Write(ScriptName) %> </b> Andrew Simpson 2004-2005
<% Case "explore"
Dim Temp as String
Dim m as Integer %>
<% For m = 0 to ubound(Directorys)
response.write(ubound(directorys))
next m %>
<% Case Else
Response.Redirect( scriptname & "?act=login") %>
<% End Select %>
</body>
</html>
<b>Now i have a feeling that the Directorys arrays and the Files arrays are wiped when it's jumps out of the script section at the top of the file but i'm not sure. </b>
Can Anyone help??