 |
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

February 10th, 2007, 01:18 AM
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can Global.asa be used to delete a folder.
My scenario is such. Upon successful login a folder is created and named the users Session.SessionId....can I use the global.asa to delete the folder on session end....so can I use the global.asa to access that users Session.SessionId as well as file.ScriptingObject? Thank you for your imput
|

February 11th, 2007, 07:02 PM
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Yes you can however there are a few hurdles to jump. This issue has been covered alot in this forum. You are luck enough to have input by the forums, IMO, most valuable person. Read imars suggestions very carefully.
http://p2p.wrox.com/topic.asp?TOPIC_ID=1774
BTW: Try searching the forum for solutions before posting. Oh and ignore ALEX_GRIM worthless posts, he was very annoying
Wind is your friend
Matt
|

February 12th, 2007, 01:33 PM
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I read that entire thread before I posted but unfortunately the bickering diluded the subject. Really what I need to know is if a session variable can be establised on session start. That variable x = Session.SessionID, and if that variable can be used on session end to delete a folder named x
|

February 12th, 2007, 04:55 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
As Matt said, yes you can do that in the Global.asa but, from the link he provided, be aware that it is NOT 100% guranteed that the Session_OnEnd event will fire. So you need to be aware of that and maybe provide a bit of garbage clean up where, if a folders creation date is older then x your system knows to delete it.
htht.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
|

February 12th, 2007, 05:02 PM
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I understand the Session_OnEnd may not fire at times and I am fine with that. I am having problems working this out though...following is my code:
Code:
Sub Session_OnStart
Session.Timeout = 10
Application.Lock
Application("dfolder") = Session.SessionId
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
dim cu,co,dfolder
set cu=Server.CreateObject("Scripting.FileSystemObject")
dfolder = Application("dfolder")
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
if cu.FolderExists("c:\inetpub\wwwroot\customers\"& dfolder)=true then
set co=cu.GetFolder("c:\inetpub\wwwroot\customers\"& dfolder)
co.Delete
set cu=nothing
set co=nothing
else
end if
co.close
cu.close
Application.UnLock
End Sub
now if I hardode the folder name here:
Code:
if cu.FolderExists("c:\inetpub\wwwroot\customers\"& dfolder)=true then
set co=cu.GetFolder("c:\inetpub\wwwroot\customers\"& dfolder
it works fine..but if the folder name is using the session.sessionId via application object (ive also tried just declaring it via dim)it doesn't delete...help?
|

February 12th, 2007, 06:18 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Solos,
Take a look at this:
Code:
Application.Lock
Application("dfolder") = Session.SessionId
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
You're assigning the current Session ID to an *application* variable. Application variables are shared by ALL users in the system. So, whenever your Session_OnEnd fires for a user, then Application("dfolder") contains the ID of the *last* user that accessed your site. I don't know about your logic, but it may be possible that at this stage, the folder hasn't been created yet.
And, even if it has, you're deleting a folder that belongs to another user.
So instead, assign a variable to Session("dfolder"). This is specific to a user. Or better yet, simply use Session.SessionId. I haven't tried it in a while, but I assume it's still available during Session_OnEnd, so you can use it directly without creating anther (session) variable.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|

February 12th, 2007, 06:28 PM
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
assigning it as an application variable was my last resort after not being able to get it to work using session.sessionId or assigning a session variable or dim to session.sessionId on session start.
in other words:
Code:
if cu.FolderExists("c:\inetpub\wwwroot\customers\"& Session.SessionId)=true then
set co=cu.GetFolder("c:\inetpub\wwwroot\customers\"& Session.SessionId)
co.Delete
doesnt work for me, nor does declaring
session("dfolder") = Session.SessionId
on session start and calling it in the above code. =(
|

February 13th, 2007, 05:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I think the things you're trying should work, so maybe something else is going wrong? I created a little sample application / global.asa with this code:
Code:
<script language="vbscript" runat="server">
Dim myFso
Dim myFile
Sub Session_OnStart
Set myFso = Server.CreateObject("Scripting.FileSystemObject")
Set myFile = myFso.OpenTextFile("c:\TestFile.txt", 8, True)
myFile.WriteLine("In OnStart, SessionId = " & Session.SessionId)
myFile.Close
Set myFile = Nothing
Set myFso = Nothing
End Sub
Sub Session_OnEnd
Set myFso = Server.CreateObject("Scripting.FileSystemObject")
Set myFile = myFso.OpenTextFile("c:\TestFile.txt", 8, True)
myFile.WriteLine("In OnEnd, SessionId = " & Session.SessionId)
myFile.Close
Set myFile = Nothing
Set myFso = Nothing
End Sub </script>
Next, I opened two different browsers and browsed to this site. As expected, I got the following stuff in the text file:
In OnStart, SessionId = 284547858
In OnStart, SessionId = 284547859
I closed my browsers and forgot about them for a while. Some time later, I looked in the file again and found this:
In OnEnd, SessionId = 284547858
In OnEnd, SessionId = 284547859
This seems to indicate that Session.SessionId is available during Session_OnEnd.
What does this sample application do for you?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Under My Umbrella by Incubus (Track 12 from the album: Morning View) What's This?
|

February 13th, 2007, 06:00 PM
|
Authorized User
|
|
Join Date: Feb 2007
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi Imar,
based on your sample I made this:
Code:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Dim myFso
Dim myFile
Sub Application_OnStart
Application("ActiveUsers") = 0
End Sub
Sub Session_OnStart
Session.Timeout = 10
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
Set myFso = Server.CreateObject("Scripting.FileSystemObject")
Set myFile = myFso.GetFolder("c:\inetpub\wwwroot\customers\"& Session.SessionId)
myFile.Delete
Set myFile = Nothing
Set myFso = Nothing
End Sub
</SCRIPT>
which works just perfectly! I only know of two things that I was originally doing differently.
1. declarling the Dims in Sub Session_onStart instead of the root of the script.
2. Sometimes, sometimes not placing the delete code inside of
Code:
Application.Lock
//delete code here//
Application.Unlock
*shrugs* Regardless, thank you for your time and attention.
|

February 13th, 2007, 06:05 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Great. Glad it's working now....
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: (She's in a) Bad Mood by Sonic Youth (Track 1 from the album: Confusion is ************) What's This?
|
Similar Threads
|
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
About Global.asa |
pbcatan |
Classic ASP Databases |
2 |
December 4th, 2006 12:40 AM |
global.asa |
vin_0x1 |
Classic ASP Components |
2 |
July 24th, 2006 01:13 AM |
Global.asa |
gmoney060 |
Classic ASP Basics |
3 |
September 25th, 2004 09:11 AM |
Global.asa |
madsmad |
ASP.NET 1.0 and 1.1 Basics |
1 |
August 17th, 2003 07:05 PM |
|
 |