473,480 Members | 3,796 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB-ASP.NET 2.0: Session Variables Question

1 New Member
I am writing a web page in VB 2005 (using .NET 2.0). I have PDF files stored in a database (also on the web server), and the user can request to view them. When they do, I pull the file out of the database and save it to the hard drive on my web server. I am trying to create a session variable of the files I create for a user during their session.

What I would like to do is keep track of the filenames so I can delete them at the end of the user's session. The reasons are twofold: 1. disk space is at a premium, and 2. this site needs to be secure, so I don't want these files "living" for very long outside of the database. I was thinking this would require a string array of the file names, but have been very confused as to variable instantiation in the Global.asax file. How do session variables work? I've googled this topic some, but I cannot really make sense of what I've seen on the web. No one seems to describe how to declare a variable and later use it. Or maybe they have and I just don't get it. Help? Please?

Option #2: Another method I thought of that might work is if I can load the PDF into a MemoryStream (or something similar) and stream this directly to the web browser rather than saving the file then directing the web browser to the file. It seems that this would be much more secure and I wouldn't have to "clean up" after each user session. I am new to web coding, so I am not sure how/if this can be done. I WOULD PROBABLY PREFER THIS METHOD IF IT IS POSSIBLE.

Thanks for any help.
Oct 14 '07 #1
1 4966
Frinavale
9,735 Recognized Expert Moderator Expert
I am writing a web page in VB 2005 (using .NET 2.0). I have PDF files stored in a database (also on the web server), and the user can request to view them. When they do, I pull the file out of the database and save it to the hard drive on my web server. I am trying to create a session variable of the files I create for a user during their session.

What I would like to do is keep track of the filenames so I can delete them at the end of the user's session. The reasons are twofold: 1. disk space is at a premium, and 2. this site needs to be secure, so I don't want these files "living" for very long outside of the database. I was thinking this would require a string array of the file names, but have been very confused as to variable instantiation in the Global.asax file. How do session variables work? I've googled this topic some, but I cannot really make sense of what I've seen on the web. No one seems to describe how to declare a variable and later use it. Or maybe they have and I just don't get it. Help? Please?

Option #2: Another method I thought of that might work is if I can load the PDF into a MemoryStream (or something similar) and stream this directly to the web browser rather than saving the file then directing the web browser to the file. It seems that this would be much more secure and I wouldn't have to "clean up" after each user session. I am new to web coding, so I am not sure how/if this can be done. I WOULD PROBABLY PREFER THIS METHOD IF IT IS POSSIBLE.

Thanks for any help.
I'm not sure how your Option 2 would work out.
I've done something simliar as what you were mentioning in the first part of your question though. See the article on Sessions.

The only Session type the Global.ascx "Session_End" method will be called for is "InProc". So, basically you just try to access the Session variable that holds the path to your file resource in the Session_End method, and if it exists then you do clean up; otherwise, don't try to delete any files.


Please note that the Session_End method is called when a SessionID is being "recycled". This usually happens when the Session times out but it could be that it doesn' t happen imediately. This is also why the Session_End method will never be executed for any other form of Sessions (because the others don't recycle SessionIDs)

I suggest doing more research on the Global.asax file and the Session_End method.

Cheers!

-Frinny
Oct 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1791
by: Simon Peng | last post by:
-- ---------------- Simon Peng xqpeng@tsinghua.org.cn
28
2417
by: Andy | last post by:
Any good resources regarding benefitis by using C3 over VB? /Andy
12
1635
by: Leo Muller | last post by:
I always thought that moving from VB.NET to C# would be very easy. Even though so far it hasn't been hard, there are some annoying things, that may have to do with my visual studio settings. -...
182
7350
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
25
1791
by: Sharrukin Amiri | last post by:
Hello, I am using VB 6.0 for many years. Everytime I needed to build software applications, I just opened VB 6.0 and started coding. I am now looking VB.NET Express Edition and I find I can no...
2
1664
by: D H | last post by:
Hi, Hi, I was looking for your opinion on VB.NET - its long-term prospects, etc. Sorry this is vague, but it's not meant to be a troll. It's a pro-VB.NET post actually. I haven't used VB or...
19
3062
by: lonelyplanet | last post by:
Hi, I'm studying for 70-306 using the book "MCAD/MCSD Visual Basic .NET Windows Applications" published by McGraw Hill (ISBN: 0-07-212583-7). I found the book has no programming exercise...
111
4718
by: =?Utf-8?B?bWFyaw==?= | last post by:
Fact Poll I made the transition from (Borland) C++ to VB.NET around 2004. I have been happy with the choice. I find I can focus more on the problem and less on being "tidy" with VB. But, I...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6908
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2994
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.